Bug Tracker

Modify

Ticket #957 (closed bug: fixed)

Opened 6 years ago

Last modified 6 years ago

serialize() doesn't work for checkboxes (jQuery 1.1.1)

Reported by: mager@… Owned by:
Priority: major Milestone: 1.2
Component: ajax Version: 1.1
Keywords: serialize Cc:
Blocking: Blocked by:

Description (last modified by john) (diff)

Short example code with two checkboxes, the second one checked:

<html> <head>

<script language="javascript" src="jquery/jquery.js"></script> <title>JS - Test</title> <script language="Javascript"> $(function() {

$('#submit').click(function(){

console.log($("input").serialize());

});

}) $("input[@type=text]").serialize(); </script>

</head> <body> <input type="checkbox" name="chk_1"><br /> <input type="checkbox" name="chk_2" checked><br /> <button id="submit" type="button">Show me!</button> </body> </html>

Firebug console shows "chk_1=on&chk_2=on", what can't be true.

Change History

comment:1 Changed 6 years ago by digid

Well the problem may be more with Firefox as the default value of a checkbox in firefox is "on"

Note that the value of the checkbox and the checked state are different.

This behavior does not happen in safari. In safari you would get this: chk_1=&chk_2=

I usually do something like this before serializing:

     $("input[@type='checkbox']").each(function() {
         this.value = this.checked?'on':'off';
     });

comment:2 Changed 6 years ago by malsup

This is a result of the core serialize method not comprehending "successful" controls.

comment:3 Changed 6 years ago by arrix

According to the roadmap, jQuery 1.2 will use new form/field serialization methods imported from Form plugin. Most related bugs will be fixed by the time.

comment:4 Changed 6 years ago by john

  • need set to Review
  • Status changed from new to closed
  • Resolution set to fixed
  • Description modified (diff)
  • Milestone set to 1.2

Fixed in jQuery 1.2.

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.