priti
priti

Reputation:

How do I populate one listbox from another listbox using JavaScript?

Can anyone tell me how to populate one listbox from another listbox item using JavaScript or ASP.NET 2.0?

Duplicate

How would I move one list box items to another listbox items in JavaScript?

For ex--My 1st listbox is Region then accourding to region selection the second listbox country will be display and accourding to country seletion state listbox will display all will come from database depends on Region Id or Country id n all

Upvotes: 1

Views: 4179

Answers (2)

Kyle B.
Kyle B.

Reputation: 5787

You may be interested in the 'Cascading Dropdown' control from the ASP.net AJAX Control Toolkit. http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx

You could also probably do this without the toolkit, using the standard UpdatePanel from ASP.net AJAX and specifing the "onChange" event of the first dropdown as a "trigger" for that UpdatePanel to be updated. Be sure you set AutoPostback="true" on the dropdown so it is fired properly is you go this route also.

Upvotes: 1

Andrzej Doyle
Andrzej Doyle

Reputation: 103817

Your question leaves out a lot of detail, but basically you would wire a function to the onchange event of the first listbox, that would populate the second listbox. If the contents would need to be dynamically loaded, you would then need to use AJAX (or similar) to pull them from the server and push them into the second box; alternatively if your contents are statically defined and not too weighty, it would be more responsive to serve them with the original document (perhaps as an associative array keyed on the values of the first listbox) and then update the second listbox based on an array lookup.

Upvotes: 0

Related Questions