checking condition onclick event of a button

Go To StackoverFlow.com

0

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?

2012-04-04 06:02
by Nitish


2

From my understanding of your question,

<input type="button" name="saveButton" onclick="Save();" value="Save" />

function Save(){
if(validateSelect())
{
    validateSave();
}
return false;
}

hope this helps

2012-04-04 06:08
by mehul9595
it helps...thn - Nitish 2012-04-04 06:48


1

<input type="button" name="saveButton" onclick="if(validateSelect()&&validateSave()){doSomething();}" value="Save" />
2012-04-04 06:06
by Avi Y


1

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.

2012-04-04 06:11
by nnnnnn
Ads