Raif
Raif

Reputation: 9259

checkbox value doesn't change when box is checked

In form submit checkbox sets value to "on" rather than "true", I explain how after submitting a form I my checkbox values are submitted as "on" rather than true.

The suggestions were that I need to have the value attribute set for it to be returned as true. So I set the value on the checkbox on the page to either true or false depending on if it's a new item or a value from the database. However, when I click the checkbox firebug shows that the value doesn't change. So how is this supposed to work?

Update a little more detail

Ok so the situation is, of course, not as simple as explained above. When posting a form I use jquery.form. What that does is it looks at all the inputs gets the values puts them in an object and then posts it to the server in an ajax call.

However, When your form has a file upload on it, what jquery.form does is it handles the file upload by creating a iframe and doing some magic( this is necessary for dealing with fileupload ) then it calls $(form).submit();

it is in this situation, where I am not submitting via ajax but rather via $.submit(), that I get the serialized value of "on" rather then true. I have looked at the code for jquery.submit and I don't really see what the heck it's doing. update Upon further consideration I guess what it's doing is just triggering the form submit the way a button with type submit would do.

Upvotes: 4

Views: 11142

Answers (1)

Josh Jones
Josh Jones

Reputation: 174

Here is a Stack Overflow post that talks about this issue specifically. It appears that jQuery uses 'on' if the checkbox value is not set to 'true' or 'false'.

Upvotes: 0

Related Questions