coupe-r Posted August 18, 2011 Share Posted August 18, 2011 I have 2 gender radio buttons: <input name="gender" type="radio" <?php if(isset($gender_error)) { echo 'class="textboxError"'; } else { echo 'class="glow"'; } ?> id="gender" value="Male" <?php if(isset($gender) && $gender == 'Male') {echo 'checked="checked"';} ?> />Male <input name="gender" type="radio" <?php if(isset($gender_error)) { echo 'class="textboxError"'; } else { echo 'class="glow"'; } ?> id="gender" value="Female" <?php if(isset($gender) && $gender == 'Female') {echo 'checked="checked"';} ?> />Female I'm passing the checked value to another PHP page via jquery: gender: document.form1.gender.value This should echo our Male, but never does. If I make it gender[0].value, it then echos Male, if I make it gender[1] it echos Female because I'm telling it the position. I'm guessing I need to change gender: document.form1.gender.value slightly, just not sure how. Any Ideas? Link to comment https://forums.phpfreaks.com/topic/245080-js-radio-button-value-not-passing/ Share on other sites More sharing options...
nogray Posted August 18, 2011 Share Posted August 18, 2011 You need to loop through the radio buttons (using a for loop) and check if the radio button is checked or not. If checked, you got your value. Since you only have 2 radio buttons only, you can also use an if,else statement Link to comment https://forums.phpfreaks.com/topic/245080-js-radio-button-value-not-passing/#findComment-1258895 Share on other sites More sharing options...
coupe-r Posted August 19, 2011 Author Share Posted August 19, 2011 This works great: $('input:radio[name=gender]:checked').val(), Link to comment https://forums.phpfreaks.com/topic/245080-js-radio-button-value-not-passing/#findComment-1259222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.