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:

snippet
$(selector).serializeArray()

jQuery serializeArray() example

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

snippet
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        var x = $("form").serializeArray();
        $.each(x, function(i, field){
            $("#results").append(field.name + ":" + field.value + " ");
        });
    });
});
</script>
</head>
<body>
<form action="">
  First name: <input type="text" name="FirstName" value="Ajeet"><br>
  Last name: <input type="text" name="LastName" value="Maurya"><br>
</form>
<button>Serialize form values</button>
<div id="results"></div>
</body>
</html>
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +