srisai
September 9th, 2004, 12:47 AM
I have a textbox, a select element and a button in HTML. If some text is entered in the textbox and the button is clicked the textbbox contents should be added as the last item of the select element and the list must scroll to the end of the select box. But the last element must not be selected. This has to be done in Javascript.
The following will code will add element to end of list but will also hight the last element, I do not want that. I just want the list to scroll to the end of the list.
<html>
<head></head>
function update(){
document.Form1.select1.options[document.Form1.select1.length]= new Option(document.Form1.edit_item.value, "")
document.Form1.select1.selectedIndex = document.Form1.select1.length-1;
document.Form1.edit_item.focus();
}
</script>
<body>
<form name = Form1>
<input type = tex name = "edit_item">
<input type='button' name='b1' value='Click Me' onClick="update()">
<select name='select1' size="5">
<option>One</option>
<option>Two</option>
</select>
</form>
</body>
</html>
The following will code will add element to end of list but will also hight the last element, I do not want that. I just want the list to scroll to the end of the list.
<html>
<head></head>
function update(){
document.Form1.select1.options[document.Form1.select1.length]= new Option(document.Form1.edit_item.value, "")
document.Form1.select1.selectedIndex = document.Form1.select1.length-1;
document.Form1.edit_item.focus();
}
</script>
<body>
<form name = Form1>
<input type = tex name = "edit_item">
<input type='button' name='b1' value='Click Me' onClick="update()">
<select name='select1' size="5">
<option>One</option>
<option>Two</option>
</select>
</form>
</body>
</html>