jQuery serializeArray()

Introduction

Output the result of form values serialized as arrays:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*from   w  w  w. jav a  2  s. com*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    let 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="CSS"><br>
  Last name: <input type="text" name="LastName" value="HTML"><br>
</form>

<button>Serialize form values</button>

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

</body>
</html>

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

$(selector).serializeArray()



PreviousNext

Related