Disabling many drop down list all at once using javascript

2k Views Asked by At
<table align="center" border="0" id="typeTable" >

<%for(int i=1;i<=count;i++){%>
    <tr id="a">         
    <td align="left" valign="top">
        <p>Problem Type <%=i+1 %></p>
        </td >
        <td align="left" valign="middle">
        <p>Number of question to generate: </p>
        </td>
        <td align="left" valign="middle" >
        <select name="type<%=i %>" id="mySelect" >
            <option>0</option>
            <option>5</option>
            <option>10</option>
            <option>20</option>
        </select>
    </td>

    </tr>
    <%}%>

    <input type="hidden" name="totalNumOfType" value="<%=count%>"/>

</table>

Hi, I have the code above to do a for loop for the table row when I get a count from the database to show how many types of problems in math topic.

The drop down menu list name I have put the int I for the name to have each row an individual name so that I can pass the value of each drop down list selected to the next page which I can do successfully.

The issue now is I have problem disabling all the drop down menu list at onece using the javascript as it will not know how many count there will be.

I have used the following code to disable the drop down menu for example.

    <script type="text/javascript">


        function disable()
        {
        document.getElementById("mySelect").disabled=true;
        }
        function enable()
        {
        document.getElementById("mySelect").disabled=false;
        }      
 </script>

I have been thinking but no avail. any help would be much appreciated. Thank you!

1

There are 1 best solutions below

2
On BEST ANSWER

did you tryed jquery prop function : $("#mySelect").prop("disabled",true) ?