开发者

Problems with submitting a form on a page with two forms

I have a page with two forms. Their ids are "delete" and "add". For the the delete form I also have a small piece of script that on submit asks if I'm sure I want to delete the selected entries:

$('form#delete').submit(function(){
   if(confirm('Are you sure you want to delete?')) { 
     return true; 
   } else { 
     return false;          
   }
});

Everything works fine for this form, but when I want to submit the second form I also get that confirmation popup. How can I get rid of that and submit the second form right?

Bellow are my two forms

<form name="delete" id="delete" method="post" action="index.php?action=delete">
<input type="checkbox" name="delete_all" id="delete_all" value="" />
<input type="checkbox" name="car[]" class="delete_checkbox" value="1" /> First car
<input type="checkbox" name="car[]" class="delete_checkbox" value="2" /> Second car
<input type="checkbox" name="car[]" class="delete_checkbox" value="3" /> Third car
<input type="submit" name="submit_delete" value="Delete" />
</form>

<form name="add" id="add" method="post" action="index.php?action=add">
Car name: <input type="text" name="car_name" value="" />
Car owne开发者_运维百科r: <input type="text" name="car_owner" value="" />
<input type="submit" name="submit_add" value="Add" />
</form>

Thank you.

Lated edit: it was a stupid error, sorry guys, one form tag wasn't properly closed.


Your code, as posted works, you can test it here. There's something outside the question going on, is your code exactly as it's posted? If so something else is attaching a confirmation handler...or trying to submit the #delete form as well (meaning it's throwing the prompt).


Psyche, I agree with Pointy and with Nick. Do other browsers also have the same problem? What happens if you change the names of the ids? Can you copy and paste your entire page here, not just snippets? Is your page perhaps displayed inside of an iframe?


Try to clear your browser cache, maybe it's in there.


Try using visual events to detect where was the event attached.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜