tags:

views:

64

answers:

4

Hello guys,

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 owner: <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.

A: 

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).

Nick Craver
The code is as posted.
Psyche
@Psyche - As I said...there's something else going on here, other code, do you have a link to the page? You can see from my example setup your code *in the question* (and *only* the code in the question) works.
Nick Craver
Sorry Nick, can't post a link to the page. But tell me what do you think it might be. What this "something else" might be?
Psyche
@Psyche - Do you have other JavaScript running? Possibly something triggering the submit of the `#delete` form as well?
Nick Craver
Nope Nick, no other js running.
Psyche
@Psyche - I can't say without seeing the page then, there's nothing wrong with what you posted, so any other cause is just a guess. Sorry I can't be of more help, but with the info you've given, there's nothing wrong.
Nick Craver
A: 

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?

shmuel613
A: 

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

elektronikLexikon
Tried that several times, still not working.
Psyche
A: 

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

SinistraD