How to stop the submission of the form using JQUERY?
Posted
by Param-Ganak
on Stack Overflow
See other posts from Stack Overflow
or by Param-Ganak
Published on 2010-04-20T10:37:59Z
Indexed on
2010/04/20
10:43 UTC
Read the original article
Hit count: 236
jQuery
Hello frineds!
I have a form which have many check boxes in it. User will check one or many checkboxes and click on Delete button which is actually submit button then the respective records for selected check boxes are get deleted.
Required operation steps are as follows:-
When user selects one or more checkboxes and clicks the submit button then a JQUERY code is get executed in which
- It should checks that if any check box is selected; if not; then is displays alert message and do not submit the form.
- If it founds that one or more checkboxes are selected it should ask user for his/her confirmation using confirm alert box about the confirmation of deletion.
- If user press YES button on confirm box then it should submit the form using javascript submit statement.
- If user pressed the NO button then it should unchecks the checked selected checkboxes and should not submit the form.
This is the JQUERY code I had written.
$(document).ready(function (){
$("#id_delete").click(function(){
var temp=$("#id_frm input:checkbox:checked");
var len=temp.length;
if(len==0)
{
alert("Please select the order.");
}
else
{
if(confirm("Are you sure to delete the selected orders."))
{
$("#id_frm").submit();
}
else
{
temp.checked=false;
}
}
});
});
Problems:
This code is not working properly. Here 1. It submits form when there is no check box is selected. 2. It submits the form when user press NO button on confirmation dialog box.
Please guide me friends in this problem.
© Stack Overflow or respective owner