Google Groups Home
Help | Sign in
Radio Buttons and .val()
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Matt Quackenbush  
View profile
 More options Jan 23, 4:22 am
From: "Matt Quackenbush" <quackfu...@gmail.com>
Date: Wed, 23 Jan 2008 03:22:37 -0600
Local: Wed, Jan 23 2008 4:22 am
Subject: Radio Buttons and .val()

Hello,

I am using the following to grab the value of a radio button:

str = $("input[name='addType']").val();

The XHTML for the radio button is as follows:

<label for="add-type-1"><input type="radio" name="addType" id="add-type-1"
value="prem" />&nbsp;Premium</label>
<label for="add-type-2"><input type="radio" name="addType" id="add-type-2"
value="std" checked="checked" />&nbsp;Standard</label>

Even though the second radio button is set with the "checked" attribute, the
jQuery snippet above always returns the value of the first radio button.  I
am obviously doing something wrong (again), but cannot seem to pinpoint the
error of my ways.

As always, thanks in advance for your assistance.

Matt


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Quackenbush  
View profile
 More options Jan 23, 4:50 am
From: "Matt Quackenbush" <quackfu...@gmail.com>
Date: Wed, 23 Jan 2008 03:50:43 -0600
Local: Wed, Jan 23 2008 4:50 am
Subject: Re: Radio Buttons and .val()

On Jan 23, 2008 3:22 AM, Matt Quackenbush wrote:

> str = $("input[name='addType']").val();

Why is it that I always find the answer just after I send the email?  God
knows I hate that.  Sorry guys.

str = $("input[name='addType']:checked").val();

Thanks again,

Matt


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Giovanni Battista Lenoci  
View profile
 More options Jan 23, 4:58 am
From: Giovanni Battista Lenoci <gian...@gmail.com>
Date: Wed, 23 Jan 2008 10:58:17 +0100
Local: Wed, Jan 23 2008 4:58 am
Subject: Re: [jQuery] Radio Buttons and .val()
Matt Quackenbush ha scritto:
> str = $("input[name='addType']").val();

Don't know if is the better way, but I use this method:

<label for="add-type-1"><input type="radio" class="radio_add_type"
name="addType" id="add-type-1" value="prem" />&nbsp;Premium</label>
<label for="add-type-2"><input type="radio" class="radio_add_type"
name="addType" id="add-type-2" value="std" checked="checked"
/>&nbsp;Standard</label>

$('.radio_add_type:checked')[0].value;

Bye


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Timothee Groleau  
View profile
 More options Jan 23, 4:35 am
From: Timothee Groleau <timothee.grol...@muvee.com>
Date: Wed, 23 Jan 2008 17:35:17 +0800
Local: Wed, Jan 23 2008 4:35 am
Subject: Re: [jQuery] Radio Buttons and .val()
Hi Matt,

On Wed, 2008-01-23 at 03:22 -0600, Matt Quackenbush wrote:
> Hello,

> I am using the following to grab the value of a radio button:

> str = $("input[name='addType']").val();

.val() returns the value of the first match element and your query
matches both radio buttons. If you want to target only the checked one,
try:

str = $("input[name=addType]:checked").val();

hth,
Tim.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Quackenbush  
View profile
 More options Jan 23, 2:49 pm
From: "Matt Quackenbush" <quackfu...@gmail.com>
Date: Wed, 23 Jan 2008 13:49:53 -0600
Local: Wed, Jan 23 2008 2:49 pm
Subject: Re: [jQuery] Re: Radio Buttons and .val()

@Timothee, Giovanni -

Thank you for your responses.  It really annoys the hell out of me that
Gmail and Google Groups both delayed your messages until I had already found
the answer in the docs, and yet the timestamps are long before they showed
up.  I even blogged about it (link below).

http://www.quackfuzed.com/index.cfm/2008/1/23/I-Love-Gmail-But

Thanks,

Matt


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
biodesign  
View profile
 More options Jan 29, 10:58 pm
From: biodesign <biodesig...@gmail.com>
Date: Tue, 29 Jan 2008 19:58:27 -0800 (PST)
Local: Tues, Jan 29 2008 10:58 pm
Subject: Re: Radio Buttons and .val()
Actually you have to use following:

var var_name = $("input[@name=radio_name]:checked").val();

On Jan 23, 11:35 am, Timothee Groleau <timothee.grol...@muvee.com>
wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Timothee Groleau  
View profile
 More options Jan 30, 1:06 am
From: Timothee Groleau <timothee.grol...@muvee.com>
Date: Wed, 30 Jan 2008 14:06:14 +0800
Local: Wed, Jan 30 2008 1:06 am
Subject: Re: [jQuery] Re: Radio Buttons and .val()

On Tue, 2008-01-29 at 19:58 -0800, biodesign wrote:
> Actually you have to use following:

> var var_name = $("input[@name=radio_name]:checked").val();

As of jQuery 1.2, the '@' is no longer necessary to match attributes;
see:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google