jquery check radio button
PHP keeps saying unidentified index: gender
? I'm not sure where the error is.
HTML:
<label>Gender:</label> <input type="radio" name="gender" value="1">Male <input type="radio" name="gender" value="0">Female
JQuery:
gender: 开发者_开发百科$("input[@name=gender]:checked").val()
PHP:
$gender = $_POST['gender'];
if($gender == '') {
echo 'Please select gender';
}
$("input[@name=gender]:checked")
That is an invalid selector in modern jQuery. This means that no element is found, and therefore no value is set for gender
. You need to remove the @
and add quote marks:
$("input[name='gender']:checked")
See the API for the attribute-equals selector.
sorted. thanks
gender: $('input:radio[name=gender]:checked').val()
精彩评论