Created
August 11, 2010 20:17
-
-
Save ten1seven/519657 to your computer and use it in GitHub Desktop.
This code makes separate radio button groups behave as a single radio group.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form> | |
<p class="radiogroup"> | |
<!-- This is one radio group --> | |
<input type="radio" name="group1" value="1" /> Item 1<br /> | |
<input type="radio" name="group1" value="2" /> Item 2<br /> | |
<input type="radio" name="group1" value="3" /> Item 3<br /> | |
<!-- This is a separate radio group --> | |
<input type="radio" name="group2" value="1" /> Item 4<br /> | |
<input type="radio" name="group2" value="2" /> Item 5<br /> | |
<input type="radio" name="group2" value="3" /> Item 6 | |
</p> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Turn multiple radio groups into one | |
$('form').delegate('.radiogroup :radio', 'click', function() { | |
$parent = $(this).closest('.radiogroup'); | |
$(':radio', $parent).attr('checked', false); | |
$(this).attr('checked', true); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code makes separate radio button groups behave as a single radio group.