You should have both <input>
s be of different names and IDs and create a new radio for each "false" state; then bind a Javascript listener to the onClick
event - using jQuery:
Code
<input type="radio" name="radio1" id="radio1" value="1"> R1
<input type="radio" name="radio1" id="radio1_2" value="0" style="display: none">
<input type="radio" name="radio2" id="radio2" value="1"> R2
<input type="radio" name="radio2" id="radio2_2" value="0" style="display: none">
$("#radio1").click(function() {
$("#radio2").prop("checked", false);
$("#radio2_2").prop("checked", true);
});
$("#radio2").click(function () {
$("#radio1").prop("checked", false);
$("#radio1_2").prop("checked", true);
});
Explanation
You set each of the two radios a different name; thus, each pertains to a different group. You must have a different radio for the false-like value of each input (its style was set to hidden, since the two radio groups should look like they're a single one). There is a problem: if you check one, the other won't be unchecked. Help!
But you want only one of them to be checked at a time. The Javascript/jQuery function deals with that as follows:
- If #radio1 is clicked (and thus checked), #radio2 must be unchecked;
- It then checks the hidden button from the radio2 group, that is, #radio2_2;
- The reverse happens if #radio2 is clicked (#radio1 is unchecked and #radio1_2, checked).
This is an elegant (albeit arguably hacky) solution to what you want to do. It could work if the hidden radios' types was hidden
instead of radio
, though I'm not sure how. Making them hidden radios makes it easy to handle them as GET/POST values.