javascriptjqueryform-submitjquery-events

How to submit form onkeyup action


I am trying to save the form onkeyup action. I am new to jQuery.

Is this possible?

I appreciate any help.

edit 1: Save the form means save to server. Is there a way to add 0.2 seconds delay.


Solution

  • This code will submit your form on keyup

    $('#element').bind('keyup', function() { 
        $('#form').delay(200).submit();
    });
    

    In this code you intercept the form submit and change it with an ajax submit

    $("#form").submit(function (event) {
        event.preventDefault();
        $.ajax({
            type: "post",
            dataType: "html",
            url: '/url/toSubmit/to',
            data: $("#form").serialize(),,
            success: function (response) {
                //write here any code needed for handling success         }
        });
    });
    

    To use the delay function you should use jQuery 1.4. The parameter passed to delay is in milliseconds.