Uncheck radio button


<input type=radio name=something value=A>
<input type=radio name=something value=B>
<input type=radio name=something value=C>

Can’t seem to find anything that does the job, so I figured I’d post here.

Does anyone know of a way to “uncheck” a radio button, but still toggle between the possible selections? Closest thing I could find required the user to double click to uncheck.

Thanks,
Han

To uncheck a radio button you simply click on one of the other buttons in the same group. A radio button group must have one of the options selected or it doesn’t make sense. If you actually have a situation where you don’t want any of them checked then you are either missing a button for the option where all the others need to be unchecked or you are using the wrong type of field.

Yeah, I know it doesn’t make sense. But the customer wants it done this way.

I need to leave the option of having nothing selected.

So you will have to use checkboxes instead and add code to deselect the others when one is selected. You can’t change the built-in functionality of radio buttons, once a radio button is selected then one of the buttons is always selected because that is what radio buttons do.

The customer wants radio buttons. Won’t change their minds.

Do as Stephen has told Han, make an additional radio button that will uncheck others. Or use check boxes. Or any event handler that will uncheck the radio buttons using javascript. Customer won’t change their minds means you are probably new and going down in front of them.

Imagine going to a car shop asking for a car that uses water as fuel and you ask the vendor that you won’t change your mind. What he will reply ?

Customer won’t change their minds means you are probably new and going down in front of them.
haha… :slight_smile: Wish it were that easy. But this is the land of government contracting. Requirements are written a year before the deployment of an application. Test cases are mapped to a requirement document. I know it sounds silly, but changing a form field from a radio button to a checkbox requires approval of a dozen people.

I understand. In that case you can add an additional radio that can be used to uncheck other buttons … or think about another way to trigger an event that will eventually uncheck the radio buttons. You need a trigger, whatever it is …

<script type="text/javascript">
rC = function(radioEl) {
	if(radioEl.checked == true) {
		radioEl.checked = false;
		return false;
	}
	else {
		radioEl.checked = true;
		return true;
	}
}
</script>
<input type=radio name=something value=A onClick="return false" onMouseDown="rC(this)">
<input type=radio name=something value=B onClick="return false" onMouseDown="rC(this)">
<input type=radio name=something value=C onClick="return false" onMouseDown="rC(this)">

that is wayyyyyyyyyy overkill and a stupid way of doing things, but for government work, at least its a start

Fantastic! That worked.

Thank you.

That code will only work in some browsers and only if JavaScript is enabled.

Simplest solution that is still workable without JavaScript.


<input type=radio name=something value=A >
<input type=radio name=something value=B >
<input type=radio name=something value=C >
<input type="radio name=something value='' style="display:none" >

and then use JavaScript to check the hidden option when required.