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? Quote Link to comment 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 Quote Link to comment 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(), Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.