开发者

How to clear form after successful submission?

I'm having a problem regarding clearing form after submission. Problem is开发者_开发技巧 it clears form when it doesn't pass the validation(s). Means it keeps on clearing though I want to just clear it when the submission is successful.

Here's the snippet

<script type="text/javascript"> 
$(document).ready(function() {
    $('#inquiry').ajaxForm({
        target: '#error',
        success: function() {
            $('#error').fadeIn('slow');
            $('#inquiry').ajaxForm().resetForm();
        }
    });
});

Sorry for my bad English as well.


try with clearForm

$(document).ready(function() { 
    var options = { 
        target:        '#output1', 
        clearForm: true // clear all form fields after successful submit 
}; 
// bind form using 'ajaxForm' 
$('#myForm1').ajaxForm(options); 
}); 

see the doucment:

clearForm
Boolean flag indicating whether the form should be cleared if the submit is successful

Default value: null

http://jquery.malsup.com/form/#ajaxForm


There is a built in method in javascript for clearing forms, it's called reset();


clearing an ajax form with jquery

$(document).ready(function() {

  var options = {
        resetForm:      true
  };

  // bind form using 'ajaxForm'
    $('#yourform_id').ajaxForm(options);
});

or

document.getElementById("myform").reset();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜