Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML refuses to check radio button by default?

Tags:

html

forms

This looks like a really basic question and I've created dozens of forms, but I just can't see what the problem is here.

I have these two radio buttons:

<input type='radio' class='free atype' value='0' name='dutch' checked='checked'/> Free<br/>
<input type='radio' class='paid atype' value='1' name='dutch' /> Paid

Obviously the first one should be checked by default.

However, when I check the second one and then refresh the page, the second radio remains checked. I know this is wrong behavior, but I can't for the life of me see what I'm doing wrong.

I'm trying this on Firefox.

like image 994
sveti petar Avatar asked Feb 21 '13 18:02

sveti petar


People also ask

Can radio buttons be deselected by default?

Give people control and align with their expectations (Good): It is better to have a selected radio button by default, given that people cannot deselect and set the button back to its original state once one has been selected. A default selection sets the correct user expectation.

Why radio button is not getting selected?

You cannot unselect radio buttons. That's because they're used if you want the user to select either option1 or option2 or option3 but prohibit selecting multiple values or leaving it empty (e.g. in case of selecting a Gender).


2 Answers

This is what's called auto complete, you can try to turn it off by adding the autocomplete="off" property to your inputs

<input type='radio' class='free atype' value='0' name='dutch' checked='checked' autocomplete="off"/> Free<br/>
<input type='radio' class='paid atype' value='1' name='dutch' autocomplete="off"/> Paid

You can also put it on the <form> the elements are in.

like image 126
Musa Avatar answered Oct 21 '22 08:10

Musa


Use Autocomplete="Off" as one of the properties in a tag

that will make some sense for that code.

like image 43
satheesh kumar Avatar answered Oct 21 '22 09:10

satheesh kumar