The following script dynamically creates a select list and moves options you create between created select-boxes.
My problem is with the dynamically assigned onfocus event handler. In IE the boxnumber variable is changed and the moveright function changes which select-box options it appends.
However in Firefox when the onfocus event handler is assigned the moveright() function does nothing. The test() function is in the script to see if the onfocus event handler reassigns the boxnumber variable; and it does.
*The script is rather long, but it seems like the question wouldn't make any sense without the whole thing.
**To make it really clear what my problem is do the following in IE and firefox:
//Save the script as an HTML file and open it. Add two items, move the first one right and then click the first box and try to move that item right.//
<HTML>
<HEAD>
<TITLE>UPDATINGS NOW</TITLE>
</HEAD>
<BODY>
<SCRIPT language="Javascript">
var newoption; var newtext; var boxnumber=0; var boxname=0;
function additem(){
with(document){
newoption = createElement("OPTION");
newtext = createTextNode(f1.t1.value);}
newoption.appendChild(newtext);
document.selectform.elements[0].appendChild(newoption);
}
function createlist(){
newlist= document.createElement("SELECT");
newlist.size=5;
newlist.name=boxname;
newlist.onfocus = function() { boxnumber = this.name; };
document.selectform.appendChild(newlist);
boxname++;
}
function moveitemright(){
with(document.selectform){
elements[boxnumber+1].appendChild(elements[boxnumber]
.options[elements[boxnumber].selectedIndex]);}
boxnumber++;
return boxnumber;
}
function moveitemleft(){
with(document.selectform){
elements[boxnumber-1].appendChild(elements[boxnumber]
.options[elements[boxnumber].selectedIndex]);}
boxnumber--;
}
function test(){
document.f1.t1.value=boxnumber;
}
</SCRIPT>
<FORM name="f1">
<INPUT type=text name="t1">
<INPUT type=button value="additem" onClick="additem()">
<INPUT type=button value="<<" onClick="moveitemleft()">
<INPUT type=button value=">>" onClick="moveitemright()">
<INPUT type=button value="createlist" onClick="createlist()">
<INPUT type=button value="test" onclick="test()">
</FORM>
<FORM name="selectform"></FORM>
</BODY>
</HTML>
My problem is with the dynamically assigned onfocus event handler. In IE the boxnumber variable is changed and the moveright function changes which select-box options it appends.
However in Firefox when the onfocus event handler is assigned the moveright() function does nothing. The test() function is in the script to see if the onfocus event handler reassigns the boxnumber variable; and it does.
*The script is rather long, but it seems like the question wouldn't make any sense without the whole thing.
**To make it really clear what my problem is do the following in IE and firefox:
//Save the script as an HTML file and open it. Add two items, move the first one right and then click the first box and try to move that item right.//
<HTML>
<HEAD>
<TITLE>UPDATINGS NOW</TITLE>
</HEAD>
<BODY>
<SCRIPT language="Javascript">
var newoption; var newtext; var boxnumber=0; var boxname=0;
function additem(){
with(document){
newoption = createElement("OPTION");
newtext = createTextNode(f1.t1.value);}
newoption.appendChild(newtext);
document.selectform.elements[0].appendChild(newoption);
}
function createlist(){
newlist= document.createElement("SELECT");
newlist.size=5;
newlist.name=boxname;
newlist.onfocus = function() { boxnumber = this.name; };
document.selectform.appendChild(newlist);
boxname++;
}
function moveitemright(){
with(document.selectform){
elements[boxnumber+1].appendChild(elements[boxnumber]
.options[elements[boxnumber].selectedIndex]);}
boxnumber++;
return boxnumber;
}
function moveitemleft(){
with(document.selectform){
elements[boxnumber-1].appendChild(elements[boxnumber]
.options[elements[boxnumber].selectedIndex]);}
boxnumber--;
}
function test(){
document.f1.t1.value=boxnumber;
}
</SCRIPT>
<FORM name="f1">
<INPUT type=text name="t1">
<INPUT type=button value="additem" onClick="additem()">
<INPUT type=button value="<<" onClick="moveitemleft()">
<INPUT type=button value=">>" onClick="moveitemright()">
<INPUT type=button value="createlist" onClick="createlist()">
<INPUT type=button value="test" onclick="test()">
</FORM>
<FORM name="selectform"></FORM>
</BODY>
</HTML>