How to submit an onkeyup action form

I am trying to save an onkeyup action form. I am new to jquery.

Is it possible.

I appreciate any help.

edit 1: Saving the form means saving to the server. Is there a way to add a delay of 0.2 seconds.

+5
source share
3 answers

This code will send your form on the keyboard

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

In this code, you intercept the submit form and change it with 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 must use jQuery 1.4. The parameter passed to the delay is in milliseconds.

+8
source

From this jQuery forum thread :

$('#element').bind('keyup', function() { $('#form').submit(); } );
+2
source

:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt-br" lang="pt-br">
<head><title>Submit after typing finished</title>
<script language="javascript" type="text/javascript">
function DelayedSubmission() {
    var date = new Date();
    initial_time = date.getTime();
    if (typeof setInverval_Variable == 'undefined') {
            setInverval_Variable = setInterval(DelayedSubmission_Check, 50);
    } 
}
function DelayedSubmission_Check() {
    var date = new Date();
    check_time = date.getTime();
    var limit_ms=check_time-initial_time;
    if (limit_ms > 800) { //Change value in milliseconds
        alert("insert your function"); //Insert your function
        clearInterval(setInverval_Variable);
        delete setInverval_Variable;
    }
}

</script>
</head>
<body>

<input type="search" onkeyup="DelayedSubmission()" id="field_id" style="WIDTH: 100px; HEIGHT: 25px;" />

</body>
</html>
+1

All Articles