views:

24

answers:

2

Here is a snippet of my form

<form action="" method="post" onsubmit="return verify()">
        <input type="submit" name="submit" value="Delete" />
        <input type="submit" name="submit" value="Save" />
</form>

As you can see I am verifying with a function called verify(). I only want to verify if they click "save", I do not want to verify for "delete".

How can I do this? Is there a way I can tell which one they clicked inside the funciton and just return true if they clicked "delete"?

+2  A: 

put "return verify() in the onclick of the button.

Iznogood
+1  A: 

You can use a global var.

HTML

<form action="" method="post" onsubmit="return verify()">
        <input type="submit" name="submit" value="Delete" onclick="window.action='delete'"/>
        <input type="submit" name="submit" value="Save" onclick="window.action='save'" />
</form>

JS

var action = '';
function verify() {
    if (action == "save") {
        // validates
    }
}
Topera
+1 for giving me a solution exactly like the one I asked for. However I believe I will accept Iznogoods answer because it requires less code.
John Isaacks
okay, it's fair. :)
Topera