AKEEL AHMED AKEEL AHMED - 7 months ago 52
Javascript Question

Inline JavaScript enable/disable select and text box on click radio button

I am trying inline script to enable disable with radio button, but it is not working. How to do that?

<form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
<br><br>
<input type="radio" name="ph" onclick=" document.getElementById("mySelect").disabled=true;" value="Disable list">DISABLE
<input type="radio" name="ph" onclick="enable()" value="Enable list">ENABLE
</form>

Answer

You can even see it at the syntax highlighter. Your JavaScript in the onclick event contains ", but they're special characters for HTML. You have to escape them with backslashes like

<tag onclick="alert(\"hello\");">