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();
});
精彩评论