It is easy to check if a radio button is checked using JQuery.
For Example:
1 2 3 4 |
<input type="radio" name="gender" value="Male" /> <input type="radio" name="gender" value="Female" /> |
In this case you can check the buttons using:
1 2 3 4 5 |
if ($('input[name=gender]:checked').length == 0) { alert("you did not choose a gender"); } |
jQuery handles syntax from left to right.
in input[name=gender]:checked
input means input tags.
[name=gender] refers to tags with the name gender within the same group.
:checked refers to checkboxes/radio buttons that are selected within the same group.
Good Example