I have a select/drop down in my HTML page which has to appear about 10 times in the page. Simple sample for that would be as below:
Qn 1: {dropdown} is a {TextField}
Qn 2: {dropdown} is a {TextField}
Qn 3: {dropdown} is a {TextField}
Where dropdown lists various options which are same and static (array of strings – no server component).
I want to create the dropdown once and use it. Can CSS have data elements for the html:select? Or how do I write javascript code to fill the select elements?
Here’s one way (using jQuery to make selecting and iterating through all dropdowns easier):
DEMO
I formatted the select options as a list and concatenated the strings to make it easy to change and reuse between pages. Simply add options to the
selectItemslist to add them to each<select>tag with the classrepeat. Give each<select>a differentnameattribute if you need the form to process them separately.