Click to See Complete Forum and Search --> : add item to listbox
shiftyshaun
11-24-2003, 07:45 AM
i have a page with a listbox and text field. The user enters some text into the textbox and hits submit, the javascript add the text into the listbox. However the listbox has option values.
<select>
<option value="20">shaun</option>
</select>
How can i add a option value as well as the display text?
regards
shaun:confused:
gil davis
11-24-2003, 07:58 AM
You would have to have another textbox for the user to add a value.
That was too obvious. Perhaps you could phrase your question better. ;)
shiftyshaun
11-24-2003, 08:06 AM
Do you know where there are any examples of this. Its easy enough to add the text value, but I m having bother with the options value??????
gil davis
11-24-2003, 08:37 AM
No, I do not know where there would be an example of this. Why would someone want to allow a user to add an option to a select box?
var newOpt = new Option();
newOpt.text = document.formName.textBox1Name.value;
newOpt.value = document.formName.textBox2Name.value;
document.formName.selectName.options[document.formName.selectName.options.length] = newOpt;
shiftyshaun
11-24-2003, 08:39 AM
just what i was needing, much appreciated! thanks
shaun