admin管理员组文章数量:1320600
Is it possible to check if (condition) onclick of an event of a button? Because I need to check two functions which are in separate .js files. Also, both the functions should return true to continue forward.
Example:
<input type="button" name="saveButton" onclick="" value="Save" />
Two functions are validateSelect() in one .js file and validateSave() in
another .js file.
validateSave() will only be called if validateSelect() returns true. So can we check onclick event of button?
Is it possible to check if (condition) onclick of an event of a button? Because I need to check two functions which are in separate .js files. Also, both the functions should return true to continue forward.
Example:
<input type="button" name="saveButton" onclick="" value="Save" />
Two functions are validateSelect() in one .js file and validateSave() in
another .js file.
validateSave() will only be called if validateSelect() returns true. So can we check onclick event of button?
Share Improve this question edited Apr 5, 2012 at 6:21 Anuj Balan 7,72923 gold badges61 silver badges94 bronze badges asked Apr 4, 2012 at 6:02 NitishNitish 8564 gold badges16 silver badges27 bronze badges3 Answers
Reset to default 3From my understanding of your question,
<input type="button" name="saveButton" onclick="Save();" value="Save" />
function Save(){
if(validateSelect())
{
validateSave();
}
return false;
}
hope this helps
<input type="button" name="saveButton" onclick="if(validateSelect()&&validateSave()){doSomething();}" value="Save" />
It doesn't matter if the functions are in different JS files (as long as both files are included).
You can say
if (validateSelect() &&validateSave()) {
/* do something */
}
With the && operator the right-hand operand will not get evaluated if the left-hand operand is false, so validateSave() will only be called if validateSelect() returns true.
You can put the above all on one line if you want to put it directly in your inline onclick.
本文标签: javascriptchecking condition onclick event of a buttonStack Overflow
版权声明:本文标题:javascript - checking condition onclick event of a button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742077277a2419481.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论