Read Only Radio Button

Read Only Radio Button

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.

Need Expert Help?

See Our Full Menu of Data Services

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

×

Love our blog? You should see our emails. Sign up for our newsletter!