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