serializeArray() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:serializeArray

Description

The serializeArray() method creates an array of objects (name and value) by serializing form values.

The following code shows how to Output the result of form values serialized as arrays:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/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 + " ");
        });//w w  w.  j  a  v a  2  s  . c o  m
    });
});
</script>
</head>
<body>

<form action="">
  First name: <input type="text" name="FirstName" value="Bond"><br>
  Last name: <input type="text" name="LastName" value="Mary"><br>
</form>

<button>Serialize form values</button>

<div id="results"></div>

</body>
</html>

Related Tutorials