jQuery serializeArray() all :inputs

5.2k views Asked by At

Does serializeArray() only work on input and textarea. how about select, checkbox, and radio buttons. I need to know which option is selected from select box and whether checkbox is checked or not. How can we get all this info in an array.

http://jsfiddle.net/bc954/1/

1

There are 1 answers

1
Austin M On BEST ANSWER

It should serialize all inputs, select, checkboxe etc...I noticed you were missing names on some of your elements, that could be why you are not seeing all elements being serialized.

<form>
    <input type="text" name="name" value="John"/>    
    <input type="text" name="password" value="password"/>
    <input type="text" name="url" value="http://asd.org/"/>
    <input type="checkbox" value="test" name="chktest" checked="checked"/>    
    <select name="stuff" id="validateAs">
        <option value="letnum">1</option>
        <option value="numbers">2</option>
        <option value="letters">3</option>
        <option value="url">4</option>
        <option value="email">5</option>
    </select>
</form>

Something like this should serialize correctly. Here's the Documentation for serializeArray().