Monday, July 8, 2013

jQuery - serializeArray

serializeArray for uncheck checkboxes

Trick:

<input type='hidden' name='check' value='false'/>
<input type='checkbox' name='check' value='true'/>


jQuery.serializeArray();

serializeArray fieldset doesn't work in IE / Safari

Use 'form' instead of 'fieldset'


<form class="myFieldset">
        <div id="divContainer">
            <div class="anotherdiv">
            <input type="text" name="testBox1" class="aclass" />
           <select name="testSel1" class="atestclass">
               <option value="car">car</option>
                        <option value="boat">boat</option>
                        <option value="plane">plane</option>
                </select>
             </div>
         </div>
</form>
<fieldset class="submit-wrap">
    <input type="submit" name="enter" id="enter" value="Enter" />
</fieldset>


Use jQuery:

$('#enter').click(function(){
    var testForm = jQuery('form').serializeArray();
    alert(testForm);
});  


Reference:
http://stackoverflow.com/questions/14852842/jquery-serializearray-doesnt-work-in-safari
http://jsfiddle.net/pCELZ/2/

0 comments:

Post a Comment