开发者

Ajax auto form submit

Does anyo开发者_C百科ne know how to automatically submit a form via AJAX, without, having to explicitly click on the submit button.

For example, say I have the following form:

<form id="form1" method="post" action="" name="form1">

Rows: <input type="text" name="rows" id="rows" /> <br/ >

Columns<input type="text" name="columns" id="columns"> <br/>

</form>

When the user fills in the columns textbox I want the form to be submitted. I know how to use AJAX, but I want it triggered on keyup event on columns.


Best way would be to make use of the OnChange event on the Columns input. Perhaps make sure rows is also filled out with valid data, then trigger the Ajax call.

Like:

$("input#columns").change(function() {
// if rows is filled out {
$.ajax({
type: 'post',
url: $("#form1").attr('action')
etc etc
})
})


You can define the $.ajax... function inside another function

function submitForm(){
   $.ajax...
}

then, you can call this function whenever you like.

$('.column').keyup(function(){
   submitForm();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜