Click to See Complete Forum and Search --> : How can you add a new item in a SELECT list?
Hello once again...
How can you add a new element in a select list, when you use javascript??
Does anyone know this, because i can't seem to find it??
Thanks
gil davis
03-12-2003, 06:24 AM
A "select" list is an array of "option" objects, and has a property called "length". You can add a new option by creating one and attaching it to the end of the array.<form>
<select name="s1">
<option>--- Select an option ---
<option>Option 1
<option>Option 2
</select>
<input type="button" value=" Add Option " onclick="this.form.s1.options[this.form.s1.options.length]=new Option('Option ' + this.form.s1.options.length)">
</form>