UmarAbbasKhan UmarAbbasKhan - 2 months ago 5
Javascript Question

How can I populate more than one select elements with one javascript function?

I have following html:

Products:



Products:<br/>
<select id="options" title="options" name="options"></select><br/>
<select id="options1" title="options" name="options"></select><br/>
<select id="options2" title="options" name="options"></select><br/>





And I have a javascript function which finds data from database using jquery ajax for these select elements. How can I place that data in all these select elements at the same time?

Answer

Assuming options is a list of <option> elements that came from the server or was built with data coming back from the server:

$('[name=options').append(options);
Comments