The gray drop-down box when only one of the radio buttons is selected

I am new to javascripts, I am trying to change the codes in a form that includes radio buttons and a drop down menu, but I would like a gray drop-down list when I select only one of the radio buttons (electronic). p>

Physical (switch) Image (switch)
Electronic (radio button)

Number of boxes [drop-down list]
I have 3 switches over the number of boxes (dropdown menu). I want the dropdown menu selection box to be grayed out when selecting "Electronic" (radio button)

<input type="radio" name="radio" id="physical" value="physical"> <label for="physical">Physical<br> <input type="radio" name="radio" id="image" value="image"> Image <br> <input type="radio" name="radio" id="electronic" value="electronic"> Electronic 

I want it to be grayed out when choosing electronic over

 <select name="NumberofBoxes" onchange="javascript:this.form.action='RecordsTransmittalForm.asp';this.form.submit();"> <option value="">--select one--</option> <% for i = 1 to 100 %> <%if clng(NumberofBoxes) = i then%> <option value="<%=i%>" selected><%=i%></option> <%else%> <option value="<%=i%>"><%=i%></option> <%end if%> <% next %> </select> 
+4
source share
2 answers

You do not explicitly indicate whether the selection of other radio buttons should re-enable your select element, but I assume that you want, in which case the following will work:

 <script> document.body.onclick = function(e) { if (!e) e = window.event; var el = e.srcElement || e.target; if(el.tagName.toUpperCase()==="INPUT" && el.name === "radio") document.getElementById("NumberofBoxes").disabled = el.value === "electronic"; }; </script> 

Not the nicest way to do this (and you should check and use addEventListener() or attachEvent() ), which makes the code even uglier), but since you did not specify any html source or anything that I just attached to the body has an onclick handler that checks whether the element with a click was entered with a specific name (where, of course, each switch in the group will have the same name). If it was a radio that was pressed, it turns on or off the indicated selection item depending on the value of the clicked radio.

Demo: http://jsfiddle.net/bcqcF/1/

+1
source

Add a click button for the switch, for example:

 <input type="radio" ... onclick="this.form.StorageType.disabled = this.checked;"> 

Of course, you can add it dynamically, but you have not provided enough information for this, the above is just an example.

0
source

Source: https://habr.com/ru/post/1397331/


All Articles