Bug Tracker

Modify

Ticket #4390 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

$('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:
Blocking: Blocked by:

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

comment:1 Changed 4 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 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.