HTML/JavaScript: Dynamically populating combobox/select options

I got a problem that how to dynamically populate values in html combo box using javascript. Or rather say, how to dynamically add options in select element of html.
here is our html code:

<select id="id_s">
 <option value="a">first</option>
 <option value="b">second</option>
</select>

Now suppose i want to add one option ‘third’, here is the code for it:

var combo = document.getElementById('id_s');
combo.options[2] = new Option ("third", "c");

Courtesy : This forum.

Advertisements

The URI to TrackBack this entry is: https://indiandeve.wordpress.com/2009/08/30/htmljavascript-dynamically-populating-comboboxselect-options/trackback/

RSS feed for comments on this post.

2 CommentsLeave a comment

  1. What kind of twat designs a webpage with white text on a yellow background!?

    • thanks for bringing my attention, this happened due to changing of theme.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: