I am working with Servlet and JSP. I have a JSP form in which I have a drop down list which is getting generated dynamically so as of now I have three options in the drop down list.
HTML CODE--
<form id='form' method='post' action='/test/'>
<select id="type" name="typeOne">
<optgroup id="first" name="First" label="FirstDiv">
<option value="value1" id="001">valuee1 count</option>
<option value="value2" id="002">value2</option>
<option value="value3" id="003">value3
</option>
</optgroup>
</select>
</form>
Now I need to disable few of the options in my above drop down list using jquery. Below is my jquery in which I am disabling the 001 and 002 options but I have hardcoded the id's in my below jquery -
<script>
$(document).ready(function () {
$(function () {
$("#type option[id='001']").prop("disabled", true);
$("#type option[id='002']").prop("disabled", true);
});
});
</script>
Below is my servlet from which I am passing a list which will have all my id's which I want to disable in my drop down list.
List<String> storeTest = new ArrayList<String>();
storeTest.add("001");
storeTest.add("002");
req.setAttribute("store", storeTest);
Problem Statement:-
Now my question is - how do I iterate store list in the jquery and disable 001 and 002 options in the drop down list?