I'm building a dynamic form which contains quite a lot of checkboxes. Because of the complexity of the form, a normal form submit isn't appropriate, and as the form is meant to be valid for multiple users at once, what I'm doing is extracting form values and storing them in JavaScript objects, before serializing them as bulk data to be sent and handled server-side.
This has worked great so far, but I've run into an issue with checkbox inputs. Despite not being checked, their value
attribute is always returned from$('input[name=checkbox_name]').val();
despite whether or not the checkbox is actually checked.
I've tried to remedy this so far by:
- Adding a value other than the default (which is
on
) - Adding a
checked
attribute, but I'm not entirely sure which values are valid and which aren't; for example, with Google Chrome's console I added achecked="checked"
attribute/value which should check the box in real time, but it didn't - Placing an hidden input element with the same
name
attribute as the checkbox withvalue=0
just before the checkbox input as per http://bit.ly/MLxCht
Any answers which detail how I can extract the current value (unchecked/checked) of a checkbox would be very much appreciated.