Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get the data of a form in javascript?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 224
    Comment on it

    We can use the serialize() method to get the data of a form. This method creates a text string in URL-encoded notation by serializing form values. It helps to select more than one element of the form.

    Syntax:

    $(selector).serilaize();
    

    Example:

    <html>
    <head>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script>
        $(document).ready(function(){
              $(document).on('submit', '#regForm', function(e) {
                e.preventDefault();
                    $(this).serialize();
                alert( $(this).serialize());
    
             });
        });
    </script>
    </head>
    <body>
    <form id="regForm" method="post" >
    
        <table  align="center">
           <tr><td>Registration Form</td></tr>
           <tr><td>Name</td><td><input type="text" id="name" name="name"></td></tr>
           <tr><td>Password</td><td><input type="text" id="password" name="pass"></td></tr>
           <tr><td>Email</td><td><input type="text" id="email" name="email"></td></tr>
           <tr><td><input type="submit" id="submit" value="register" align="middle"></td></tr>
        </table>
    </form>    
    </body>
    </html>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: