Side navigation
#3609 closed bug (invalid)
Opened November 14, 2008 05:45PM UTC
Closed March 21, 2009 02:37PM UTC
Last modified March 15, 2012 12:04AM UTC
setting val() of radio or checkbox to single value sets "value" instead of "checked"
Reported by: | jhohm | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.3 |
Component: | core | Version: | 1.2.6 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
The documentation of val() says, in the second section for val(val):
"Checks, or selects, all the radio buttons, checkboxes, and select options that match the set of values."
And the example code shows that it works given a single non-Array value to select the option on a non-multiple select:
$("#single").val("Single2");
But this does not work for radio or checkbox inputs. Given this HTML:
<input type="radio" name="ordinal" value="1">First</input>
<input type="radio" name="ordinal" value="2">Second</input>
code like this:
$("[@name='ordinal']").val("2");
surprisingly ends up setting the "value" attribute of all the radio buttons to "2" like this:
<input type="radio" name="ordinal" value="2">First</input>
<input type="radio" name="ordinal" value="2">Second</input>
instead of setting the "checked" attribute on the radio button with value "2" as expected, like this:
<input type="radio" name="ordinal" value="1">First</input>
<input type="radio" name="ordinal" value="2" checked>Second</input>
Patch to provide the expected (and in my opinion documented) behavior attached.
How would you set the value attribute of a checkbox or radio element then?
The current behavior allows you to choose the checkbox/radio by passing in an array with a single element.