JQuery Forms Submit

From CoderLearner
Jump to: navigation, search

Description

Bind on the submit event for the form which associated with the JavaScript event.

Syntax

$.submit();

$.submit( handler ( event object ) );

$.submit( [event data], handler(event object) );

Example

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>submit</title>
        <script 
            type="text/javascript" 
            src="jquery.min.js">				 
        </script>
        <script>
            $().ready(function() {
                $('form').submit(function(){
                    alert('submit it');
                    return false; 
                });
            });
        </script>
    </head>
    <body> 
        <form>
            <input type="text" name="first"/>
            <input type="text" name="last"/>
            <input type="submit" value="Submit"/>
        </form>
    </body>
</html>

Example 2

Click on the URL to submit a form.

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Serialize</title>
        <script 
            type="text/javascript" 
            src="/lib/jquery-1.7.2.min.js">				 
        </script>
        <script>
            $().ready(function() {
                $('#my_submit').click(function(){
                    $('form').submit();
                });
                
                $('form').submit(function(){
                    var d=$(this).serialize();
                    alert(d);
                    return false; 
                });
            });
        </script>
    </head>
    <body> 
        <form>
            <input type="text" name="first"/>
            <input type="text" name="last"/>

            <a href="#" id="my_submit">Click to submit</a>
        </form>
    </body>
</html>

Try It