serializeArray()
method
The serializeArray() method creates an array of objects
(name and value) by serializing form values.You can select one or more form
elements (like input and/or text area), or the form element itself.
Syntex:
$(selector).serializeArray()
|
<!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 + " ");
});
});
});
</script>
</head>
<body>
<form action="">
First name: <input
type="text" name="FirstName"
value="Nitin"><br>
Last name: <input
type="text" name="LastName"
value="Chauhan"><br>
</form>
<button>Serialize form values</button>
<div id="results"></div>
</body>
</html>
|