473,396 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get last active element..

Hi,

I have three textareas and four buttons within a form. The buttons has
often used text as value. When I press a button I whant the assigned
text to be added in whatever textareas im currently in (the one with
cursor blinking). Is this possible with Javascript?

--
Tommy Myrvoll

Nov 2 '05 #1
5 11392
Ivo
<ry*********@gmail.com> wrote

I have three textareas and four buttons within a form. The buttons has
often used text as value. When I press a button I whant the assigned
text to be added in whatever textareas im currently in (the one with
cursor blinking). Is this possible with Javascript?


var lastarea, // global variable to remember current element
a = document.getElementsByTagName( 'textarea' ), i = a.length;
while( i-- ) {
a[i].onfocus = setlast; // initialize
}

function setlast( e ) {
e = e || window.event || {};
var o = e.srcElement || e.target;
lastarea = o;
}

Now when the button is pressed, you simply update "lastarea.value" with
whatever the button is supposed to add.
hth
ivo
http://4umi.com/web/javascript/
Nov 2 '05 #2
<ry*********@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Hi,

I have three textareas and four buttons within a form. The buttons has
often used text as value. When I press a button I whant the assigned
text to be added in whatever textareas im currently in (the one with
cursor blinking). Is this possible with Javascript?

--
Tommy Myrvoll


Will this help?

<html>
<head>
<title>often.htm</title>
<script type="text/javascript">
var what;
function fokus(that) {
what = that;
}
function often(that) {
if (what == null) return;
what.value = that.value;
}
</script>
</head>
<body>
<form>
<input type="reset" value="Reset">
<br><textarea name="a1" id="a1" cols="40" rows="3"
onfocus="fokus(this)"></textarea>
<br><textarea name="a2" id="a2" cols="40" rows="3"
onfocus="fokus(this)"></textarea>
<br><textarea name="a3" id="a3" cols="40" rows="3"
onfocus="fokus(this)"></textarea>
<br><input type="button" value="often used text 1"
onclick="often(this)">
<br><input type="button" value="often used text 2"
onclick="often(this)">
<br><input type="button" value="often used text 3"
onclick="often(this)">
<br><input type="button" value="often used text 4"
onclick="often(this)">
</form>
</body>
</html>
Nov 2 '05 #3

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:ZK********************@comcast.com...
<ry*********@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Hi,

I have three textareas and four buttons within a form. The buttons has
often used text as value. When I press a button I whant the assigned
text to be added in whatever textareas im currently in (the one with
cursor blinking). Is this possible with Javascript?

--
Tommy Myrvoll


Will this help?

<html>
<head>
<title>often.htm</title>
<script type="text/javascript">
var what;
function fokus(that) {
what = that;
}
function often(that) {
if (what == null) return;
what.value = that.value;
}
</script>
</head>
<body>
<form>
<input type="reset" value="Reset">
<br><textarea name="a1" id="a1" cols="40" rows="3"
onfocus="fokus(this)"></textarea>
<br><textarea name="a2" id="a2" cols="40" rows="3"
onfocus="fokus(this)"></textarea>
<br><textarea name="a3" id="a3" cols="40" rows="3"
onfocus="fokus(this)"></textarea>
<br><input type="button" value="often used text 1"
onclick="often(this)">
<br><input type="button" value="often used text 2"
onclick="often(this)">
<br><input type="button" value="often used text 3"
onclick="often(this)">
<br><input type="button" value="often used text 4"
onclick="often(this)">
</form>
</body>
</html>


Change

what.value = that.value;

to

what.value += that.value;

to append the value to the textareas.

Note the value is appended with adding a space
or a line feed. Do you need either?
Nov 2 '05 #4
Ivo wrote:
<snip>
var lastarea, // global variable to remember current element
a = document.getElementsByTagName( 'textarea' ), i = a.length;
while( i-- ) {
a[i].onfocus = setlast; // initialize
}

function setlast( e ) {
e = e || window.event || {};
var o = e.srcElement || e.target;
lastarea = o;
}

<snip>

Given that you are assigning - setlast - to the - onfocus - property of
the textarea, so it will be called as a method of the textarea element:-

function setlast(){
lastarea = this;
}

- should be sufficient.

Richard.
Nov 2 '05 #5

McKirahan wrote:
....
<script type="text/javascript">
var what;
function fokus(that) {
what = that;
}
function often(that) {
if (what == null) return;
what.value = that.value;
}
</script>

....

Just what I needed. Thanks a lot

--
Tommy

Nov 2 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Al Franz | last post by:
Look at the following web page test. http://netmation.com/test61.htm Why is there blank space on the 4th row, can not get rid of it. Using the latest IE 6
4
by: crhaynes | last post by:
I'm having trouble with my CSS. My links are black, my hover is orange and my active link is red. When I select a link it turns red but i does not retain that color when the selected page loads. ...
7
by: McKirahan | last post by:
What is "active content"? My ASP page just returns HTML.... I have a page with an .htm extension that has a form whose action is an ASP page which generates a report after updating a database...
3
by: Robert Neville | last post by:
How do you return the last Active Control when the control is on a tab control? Screen.ActiveControl does not seem to work. Here's the statement that my code uses. Set ctlOld =...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
2
by: Sharkie | last post by:
I'm relatively new to XSLT, having strong background in bunch of other programming languages (Perl, Java, etc.). I'm writing an XSLT stylesheet, converting XML into HTML. Everything works just...
9
by: newcomsas | last post by:
Hello. I'm working on a problem related with CSS and javascript: I have got a link on a page and a stylesheet file that makes the background color change when users click on it. Is there...
0
by: Mark | last post by:
Hi there This is my menu (well part of it; it is generated dynamicaly). <ul> <li><a href="#">Item 1</a></li> <li><a href="#">Item 2</a></li> <li><a href="#">Item 3</a> <ul> <li><a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.