Serialize method in jQuery

The serialize() method is an inbuilt method in jQuery which is used to create a URL encoded text string by serializing form values. This method can act on a jQuery object that has selected individual form controls, such as input, textarea etc. or the form element itself. Syntax
$(selector).serialize()
example
$("form" ).submit(function( event ) { var querystring = $(this).serialize(); alert(querystring); });
<form action="#" id="input_form"> First Name: <input type="text" name="firstName" /><br /> Last Name: <input type="text" name="lastName" /><br /> Email: <input type="text" name="email" /><br /> <input type="submit" value="send" name="submit" /> </form>
Full Source
<!DOCTYPE html> <html lang="en"> <head> <title>jQuery serialize() method</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("form" ).submit(function( event ) { var querystring = $(this).serialize(); alert(querystring); }); }); </script> </head> <body> <form action="#" id="input_form"> First Name: <input type="text" name="firstName" /><br /> Last Name: <input type="text" name="lastName" /><br /> Email: <input type="text" name="email" /><br /> <input type="submit" value="send" name="submit" /> </form> </body> </html>
Only form elements are examined for inputs they contain, in all other cases the input elements to be serialized should be part of the set passed to the .serialize() method . Selecting both the form and its children in a set will cause duplicates in the serialized string.