How to validate for save but not for delete?
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"?
Place return verify();
in the onclick
of the button.
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
}
}
精彩评论