A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Joined: Oct 16, 2011
Oct 23, 2011 13:34:40
Hi i wanted to add attributes to a list box dynamically , say I have a list box as such
<select name="list" size="5" id="list_box"> <option>item one</option> <option>item two</option> </select>
script function how can I add another item to the list box dynamically. I know .setAttribute() wont do the trick . I actually want to add <option> attributes dynamically such as
<select name="list" size="5" id="list_box"> <option>item one</option> <option>item two</option> <option>...</option> <option>...</option> </select>
any suggestions on how i could accomplish this??
Author and ninkuma
Joined: Jan 10, 2002
Oct 23, 2011 13:39:23
not attributes. You need to use the DOM manipulation API to create the new element and attach it to the DOM at the correct location.
Investigate methods such as document.createElement() and document.createTextNode(), as well as the appendChild() method of Element.
Asking smart questions
Books by Bear
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
I want to fill a Listbox with values dynamically using JSP when I press a button
In List Highlighting previous selected values
Selecting option in second selectOneMenu not setting property value
How to get last selected value in list box?
How many attributes can a servlet have?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014