0

I've read the jquery documentation and it seems like input elements like checkbox, radio and multiple selects will not be serialized if they are blank. I've also read this thread. jQuery serialize does not register checkboxes which has given me quite good information about the problem.

But what I want here is, "Is there any elegant solution to this problem?", I just want a blank value if those elements are left blank.

Any suggestions would be great.

Community
  • 1
  • 1
user2906838
  • 1,178
  • 9
  • 20

1 Answers1

1

On the same example this is also mention. Try this:

/* Get input values from form */
values = jQuery("#myform").serializeArray();

/* Because serializeArray() ignores unset checkboxes and radio buttons: */
values = values.concat(
        jQuery('#myform input[type=checkbox]:not(:checked)').map(
                function() {
                    return {"name": this.name, "value": 'off'}
                }).get()
);
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
  • Yes, But I'm searching for something elegant solution, since I have to do same with radio and multiple select too. – user2906838 Aug 16 '16 at 10:40