Processing math: 100%

jQuery serialize()

Some important features of the jQuery serialize() method are;

  • jQuery serialize() method creates a text string in standard URL-encoded notation.
  • It is used in form controls.
  • It serializes the form values, the serialized values can then be used in the URL query string.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ (selector).serialize()
$ (selector).serialize()
$ (selector).serialize()

Example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
("div").text(("form").serialize());
});
});
</script>
</head>
<body>
<form action="">
First name: <input type="text" name="Mailid" value="test.com"><br>
Last name: <input type="text" name="UserName" value="Jai"><br>
</form>
<br>
<button>Serialize</button>
<br>
<div></div>
</body>
</html>
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ ("div").text(("form").serialize()); }); }); </script> </head> <body> <form action=""> First name: <input type="text" name="Mailid" value="test.com"><br> Last name: <input type="text" name="UserName" value="Jai"><br> </form> <br> <button>Serialize</button> <br> <div></div> </body> </html>
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").text($("form").serialize());
});
});
</script>
</head>
<body>
<form action="">
First name: <input type="text" name="Mailid" value="test.com"><br>
Last name: <input type="text" name="UserName" value="Jai"><br>
</form>
<br>
<button>Serialize</button>
<br>
<div></div>
</body>
</html>