Bug Tracker

Opened 10 years ago

Closed 10 years ago

#4390 closed bug (invalid)

$('input[type=checkbox]').val() doesn't return checked or unchecked status

Reported by: andras Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:

Description

$('input[type=checkbox]').val() returns always the attribute value of the input and not the checked or unchecked status wich really tells the user value.

Change History (2)

comment:1 Changed 10 years ago by JDay

Checkbox inputs store their checked state in the presence of a 'checked' attribute, not in 'value'. Any value, for 'checked' will result in a checked input, i.e. <input type="checkbox" checked="false" value="false" /> would be checked. The absence of the 'checked' attribute will prevent the value from being sent at all on a form submit. The correct method for determining check state is: $('input[type="checkbox"]').is('[checked]')

comment:2 Changed 10 years ago by dmethvin

Resolution: invalid
Status: newclosed

You haven't said what value you would expect from .val() when the checkbox isn't checked but whatever it returned would be a surprise for existing code. Since .val() is a symmetrical getter/setter for other elements, I don't think a special case for checkboxes is warranted.

Note: See TracTickets for help on using tickets.