Checkbox - assigning unchecked vaue

by Aakash Chakravarthy

HTML

<form>
  <input type="checkbox" name="test" value="1" />
</form>
<button id="b">submit</button>

JavaScript

$('#b').click(function () {
  alert($('form').serialize());
});


$('input[type=checkbox]').each(function(){
    ff = $(this).clone().attr('type', 'hidden').attr('value', 0);
    $(this).before(ff);
});