William wrote:
I tried to update a scrolling_list with the following:
function saveText( scroll_list, t_area, listToBeUpdated ) {
var updated = new Option();
updated.value = t_area.value;
updated.text = t_area.text;
scroll_list.options[scroll_list.selectedIndex] = updated;
}
but I get "Undefined" in the position with the new Option()
(i.e. "updated").
Why and how to fix this?
Your code is incomplete, which makes it hard to narrow down the
problem. I'm assuming a "scrolling_list" means a select-tag with size1.
How should your "update" action behave ? First empty the box or just
add new text/value pairs ? I'm assuming the first, otherwise just
comment the while loop in the code.
------------------------
<html>
<head>
<script language="javascript">
function saveText() {
// empty box
while (document.forms[0].scroll_list.options.length)
document.forms[0].scroll_list.options[0] = null;
// put new content in the box
document.forms[0].scroll_list.options[document.forms[0].scroll_list.length]
= new Option("brown", "6");
document.forms[0].scroll_list.options[document.forms[0].scroll_list.length]
= new Option("black", "7");
}
</script>
</head>
<body>
<form>
<select size="3" name="scroll_list">
<option value="1">white</option>
<option value="2">blue</option>
<option value="3">green</option>
<option value="4">red</option>
<option value="5">yellow</option>
</select>
<input type="button" value="Update" onClick="saveText();">
</form>
</body>
</html>
--
Bart