I have two select boxes and two text areas.
An user would first click in a text area
and then go on selecting elements (one at
at a time) from any of the select boxes.
I wish to copy selected items to THAT text
area which user had clicked earlier.
So, in a sense, my script has to "remember" which text area was clicked before.
How do I achieve this in Javascript?
To make things clear, here is my HTML page
code. (Say user clicks in X-expression box
first and then clicks on an option from either FIRSTBOX or SECONDBOX. On clicking
they get copied to X-expression box. Then user clicks in Y-expression box and whenever
user clicks on an option from either select
boxes, they should get copied to Y-expression box now). Your help is appreciated!!
HTML+Javascript code
TO TEST JAVASCRIPT TO SELECT FROM A SELECT LIST AND COPY TO A DESIRED TEXT AREA
<hr>
<form name="myform" method=post >
<strong> FIRSTBOX </strong>
<SELECT size = "4" NAME="firstbox" onchange="CopySelected(document.myform.firstbox)">
<OPTION> Sun
<OPTION> Silicon Graphics
<OPTION> Intel
<OPTION> Motorola
<OPTION> TI
<OPTION> BMW
<OPTION> Ferrari
</SELECT>
<strong> SECONDBOX </strong>
<SELECT size = "4" NAME="secondbox" onChange="CopySelected(document.myform.secondbox)">
<OPTION> USA
<OPTION> UK
<OPTION> China
<OPTION> Malasiya
<OPTION> Singapore
<OPTION> Indonesia
</SELECT>
<hr>
X-Expression
<TEXTAREA NAME="xexpr" ROWS="4" COLS="20" onclick="ShowIt(xexpr)"> test1
</TEXTAREA>
<br>
Y-Expression
<TEXTAREA NAME="yexpr" ROWS="4" COLS="20" onclick="ShowIt(yexpr)"> test2
</TEXTAREA>
<hr>
<SCRIPT LANGUAGE="JavaScript">
var t;
function ShowIt(object){
t = object.name;
}
function CopySelected(mybox){
k = mybox.options[mybox.selectedIndex].text;
document.myform.xexpr.value = k;
// currently they get copied to xexpr box
// but I want to memorize box in "t".
}
</SCRIPT>
</form>
</BODY>