Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

jQuery serializeArray()


The jQuery serializedArray() Method is used to create a JavaScript array of objects by serializing form values. It operates on a jQuery collection of forms and form controls. You can select one or more form elements such as <input>, <textarea> or the form element itself.

Syntax:

  1. $(selector).serializeArray()

jQuery serializeArray() example

Let’s take an example of serializeArray() method.

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js”></script>
  5. <script>
  6. $(document).ready(function(){
  7.     $(“button”).click(function(){
  8.         var x = $(“form”).serializeArray();
  9.         $.each(x, function(i, field){
  10.             $(“#results”).append(field.name + “:” + field.value + ” “);
  11.         });
  12.     });
  13. });
  14. </script>
  15. </head>
  16. <body>
  17. <form action=“”>
  18.   First name: <input type=“text” name=“FirstName” value=“Ajeet”><br>
  19.   Last name: <input type=“text” name=“LastName” value=“Maurya”><br>
  20. </form>
  21. <button>Serialize form values</button>
  22. <div id=“results”></div>
  23. </body>
  24. </html>

Comments

comments