Disabling a Radio Button

Question: How do I disable a radio button in a form (making it not selectable)?

Answer: To make a radio button not selectable, in the button's

INPUT
tag you can use an
onclick
event handler like this:
<INPUT type="radio" name="myButton" value="theValue"
onclick="this.checked=false;
alert('Sorry, this option is not available!')">
In the example below, the "Courier delivery" option is disabled. Try it now - you'll get an alert box with the text Sorry, this option is not available!
 Delivery method (choose one):
download
regular mail
courier delivery (temporarily unavailable) 
Note, however, that the above trick won't work if the user has disabled JavaScript. Nevertheless, even without relying on client-side scripting, you can still disable a radio button (as well as form elements of other types) using the attribute
disabled
within the HTML tag that defines the form element, for example:
<input type=radio name=r1 disabled>
. In most browsers, the disabled form element will be grayed out, like this:
 Delivery method (choose one):
download
regular mail
courier delivery (temporarily unavailable) 

Copyright © 1996-2018, JavascriptFAQ.net.