开发者

How to validate for save but not for delete?

开发者 https://www.devze.com 2023-01-12 23:42 出处:网络
Here is a snippet of my form <form action=\"\" method=\"post\" onsubmit=\"return verify()\"> <input type=\"submit\" name=\"submit\" value=\"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
    }
}
0

精彩评论

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