开发者

jquery check radio button

开发者 https://www.devze.com 2023-02-04 07:23 出处:网络
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=\"r

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()
0

精彩评论

暂无评论...
验证码 换一张
取 消