/    Sign up×
Community /Pin to ProfileBookmark

onClick with 2 functions

I wish to have a button call 2 different functions when its clicked…is it possible? The two functions are Validate() and Test()

onClick=”Validate(); Test()”

Will the above work?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterMar 22.2006 — It will definately call both of them.

However I get the sense you want to stop a form from submitting which is done like so:
<i>
</i>&lt;form onsubmit="return Validate()"&gt;

If you want the Test function to fire regardless the value returned from Validate in addition to firing the Validate funtion prior to the Test function as well as return the value of Validate to the event handler, it would look like this:
<i>
</i>&lt;form onsubmit="return (function(){var r=Validate();Test();return r;})();"&gt;

Or you [i]could[/i] just edit the Validate function and add a function call to Test() prior to the "return" statement.
Copy linkTweet thisAlerts:
@felgallMar 22.2006 — or if the order in which the functions run doesn't matter you could use

onsubmit="test(); return Validate()"
Copy linkTweet thisAlerts:
@dzirkelbauthorMar 22.2006 — Thanks guys, that answered my question!
×

Success!

Help @dzirkelb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...