admin管理员组文章数量:1327714
I want to disable the submit button when a user submits the form so that he may not click the submit button twice.
So I coded the following javascript in my page
$(document).ready(function(){
$("form").submit(function(){
$("form").find('input[type=submit]').attr('disabled', 'disabled');
});
})
This works great. But when I applied the jquery validate library and appended the following code
$(document).ready(function(){
$("form").submit(function(){
$("form").find('input[type=submit]').attr('disabled', 'disabled');
});
$("form").validate({
errorClass: "jqueryError",
errorElement: 'label',
success: 'jqueryValid',
messages: {
TopicCategory: {
required: 'Please choose a category for topic.'
},
TopicSubcategoryId: {
required: 'Please choose a subcategory for topic.'
},
TopicTitle: {
required: 'Please enter a title for topic.'
}
}
});
})
The submit button got disabled after submitting form even if there are inplete inputs in the website (i.e. form with errors and user is asked to fill them properly).
and when the user pletes the form correcting all errors the submit button is disabled.
How do I first check if there are no errors in the form and then disable the submit button and then submit it finally.
Thanks
I want to disable the submit button when a user submits the form so that he may not click the submit button twice.
So I coded the following javascript in my page
$(document).ready(function(){
$("form").submit(function(){
$("form").find('input[type=submit]').attr('disabled', 'disabled');
});
})
This works great. But when I applied the jquery validate library and appended the following code
$(document).ready(function(){
$("form").submit(function(){
$("form").find('input[type=submit]').attr('disabled', 'disabled');
});
$("form").validate({
errorClass: "jqueryError",
errorElement: 'label',
success: 'jqueryValid',
messages: {
TopicCategory: {
required: 'Please choose a category for topic.'
},
TopicSubcategoryId: {
required: 'Please choose a subcategory for topic.'
},
TopicTitle: {
required: 'Please enter a title for topic.'
}
}
});
})
The submit button got disabled after submitting form even if there are inplete inputs in the website (i.e. form with errors and user is asked to fill them properly).
and when the user pletes the form correcting all errors the submit button is disabled.
How do I first check if there are no errors in the form and then disable the submit button and then submit it finally.
Thanks
Share Improve this question asked May 7, 2010 at 16:31 Gaurav SharmaGaurav Sharma 2,8281 gold badge37 silver badges55 bronze badges3 Answers
Reset to default 7Add the following parameter to jQuery Validate:
submitHandler: function(form) {
$(':submit', form).attr('disabled', 'disabled');
form.submit();
}
I have not used the jquery validator plugin but reading the docs here
http://docs.jquery./Plugins/Validation/validate
you could
1) disable the button in the submitHandler callback
2) leave your existing disable code, but then re-enable the button in the invalidHandler callback
I have not started with jQuery yet. But I think, you can do something like this:
$(document).ready(function(){
$("form").submit(function(){
});
$("form").validate({
errorClass: "jqueryError",
errorElement: 'label',
success: 'jqueryValid',
messages: {
TopicCategory: {
required: 'Please choose a category for topic.'
},
TopicSubcategoryId: {
required: 'Please choose a subcategory for topic.'
},
TopicTitle: {
required: 'Please enter a title for topic.'
}
}
$("form").find('input[type=submit]').attr('disabled', 'disabled');
});
})
版权声明:本文标题:javascript - how do I disable the submit button when the form gets submitted without any errors - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742214890a2434386.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论