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.


> 
> 
> 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 via email to