Read Only Radio Button

Dev

Read Only Radio Button

by Kyle Godard

Consider the following situation: you would like a set of radio buttons on a form that will have a value preselected. You don’t want to give the user the option to change the selected radio button, but you do want to submit that value with the form.

Using the disabled attribute doesn’t work because it doesn’t submit the value with the form. Using the readonly attribute doesn’t work with radio buttons.

This can be accomplished by simply adding an onclick=”return false;”. This also allows the radio buttons to look normal without being grayed out.

The only caveat I’ve found with this is that the selection has to be made ahead of time or the first one the user clicks on will be selected and then the user cannot select another one. One way of dealing with this is by using a default value you would like submitted with the form if none of the values are selected. Then just use a style=”display:none;” to hide this button from the user. All the other radio buttons will remain unselected and unable to change.

More About the Author

Kyle Godard

Software Engineer
Read Only Radio Button Consider the following situation: you would like a set of radio buttons on a form that will have a value preselected. You don’t want to ...
A better way to handle variables when nesting CFLOOP If you try to reference a value from the outer query within a nested CFLOOP you normally get only the first value from the outer query ...

See more from this author →

Subscribe to our newsletter

  • I understand that InterWorks will use the data provided for the purpose of communication and the administration my request. InterWorks will never disclose or sell any personal data except where required to do so by law. Finally, I understand that future communications related topics and events may be sent from InterWorks, but I can opt-out at any time.
  • This field is for validation purposes and should be left unchanged.

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072