Jump to content

JS radio button value, not passing


coupe-r

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.