HTML select list problem

Shikha Gupta

New Member
There is a select list box(having a dispaly size of 5) and 2 buttons-Up and Down to move the elements in the list.In netscape,if I select an element which does not lie in visible part of the list and press the Up button,then the control goes to the first part of the list,though the control should have been in the portion where the selected element is.
This works for Internet explorer but not for netscape.Please suggest.Below is the sample code.



<html>
<head><title>TestPage</title></head>

<SCRIPT LANGUAGE="JAVASCRIPT">
function down(fbox) {
for(var i=0; i<fbox.options.length; i++) {
if(fbox.options.selected && fbox.options.value != "") {
if(i ==fbox.options.length-1)
return;
var no = new Option();
no.value = fbox.options.value;
no.text = fbox.options.text;
fbox.options.value = fbox.options[i+1].value;
fbox.options.text = fbox.options[i+1].text;
fbox.options[i+1] = no;

}
}

} //down()


function up(fbox) {
for(var i=0; i<fbox.options.length; i++) {
if(fbox.options.selected && fbox.options.value != "") {
if(i==0)
return;
var no = new Option();
no.value = fbox.options.value;
no.text = fbox.options.text;
fbox.options.value = fbox.options[i-1].value;
fbox.options.text = fbox.options[i-1].text;
fbox.options[i-1] = no;
fbox.focus();
}
}
} //up()




</script>
<body>
<form name="form1" >

<select name="select1" size=5>
<option value=2>Test1</option>
<option value=13>Test2</option>
<option value=14>Test3</option>
<option value=4>Test5</option>
<option value=6>Test6</option>
<option value=7>Test7</option>
<option value=8>Test8</option>
<option value=9>Test9</option>
<option value=10>Test10</option>
<option value=11>Test11</option>
<option value=12>Test12</option>

</select>

<input type =button name="UP" value="Up" onclick="up(document.form1.select1)">
<input type =button name="DOWN" value="Down" onClick="down(document.form1.select1)">


</form>
</body>
</html>
 
Top