Opened 16 years ago
Closed 15 years ago
#957 closed bug (fixed)
serialize() doesn't work for checkboxes (jQuery 1.1.1)
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | major | Milestone: | 1.2 |
Component: | ajax | Version: | 1.1 |
Keywords: | serialize | Cc: | |
Blocked by: | Blocking: |
Description (last modified by )
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 (4)
comment:1 Changed 16 years ago by
comment:2 Changed 16 years ago by
This is a result of the core serialize method not comprehending "successful" controls.
comment:3 Changed 15 years ago by
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 15 years ago by
Description: | modified (diff) |
---|---|
Milestone: | → 1.2 |
need: | → Review |
Resolution: | → fixed |
Status: | new → closed |
Fixed in jQuery 1.2.
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: