/    Sign up×
Community /Pin to ProfileBookmark

How does onclick work? And how can I control it?

Hello there,

I am interested in learning about the onclick event and how I can make a function in it and then exit the onclick or stop it running anymore code.

for example: I have:

[CODE]
document.getElementById(element1).onclick = function {
// lots of code in a function for element1’s onclick event.
// a timer is set to do more code soon; but not if the function
// below stops it first…
tempvar1 = setTimeout(dosomecodefunc, 2000);
}

document.getElementById(element1).onclick = function {
// a whole bunch of code that is running.
// some code to tell onclick to stop running
// any code (including any functions, like above)
}
[/CODE]

Gah, this is frustrating, because I know there is a clearTimeout(); I don’t want to know that…
what I want to know is; is there something like exit(onclick()); or something.

I am trying to make it easy to explain my question, because in the future I will use the solution for a bigger problem where clearTimeout() would not suffice.

I am only a novice in Javascript, and as such I require help for these things (which may seem simple); but I am capable of researching this further; if I am given a few leads.

The thing I was hoping to achieve from this post was a more understandable answer than what I would find in Javascript Standards or something.


_____________________

“or something” Score increased to 5000 points.

Congratulations you now have a habit.


_____________________

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@heirophantJan 04.2007 — Just make a function for that the onclick that decides what to do based on a booleon global variable.
Copy linkTweet thisAlerts:
@jawbootauthorJan 04.2007 — Thank you, your solution would work in many situations, but unfortunately not mine.

Yes, maybe it will be good for me to explain the more complicated situation I am in.

I am using Yahoo! User Interface; and it has its own way of entering code into the onclick...

[CODE]YAHOO.util.Event.on(a, 'click', yahooutilityanimationvariable.animate, yahooutilityanimationvariable, true);[/CODE]

And then I have my function
[CODE]document.getElementById(elementid1).onclick = function {
//code here...
//start conditional statement
//code to stop onclick from executing code here...
//end conditional statement
}[/CODE]


But how can I tell my function to stop the Yahoo!-made onclick (function, IDontKnow?) from executing when My Onclick Function decides to stop all onclick code from continuing.

You see, I have no real direct access to the Yahoo! onclick function; all I can do is set it.; so, how can I control the onclick event? Stop it, or exit it.
×

Success!

Help @jawboot 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.19,
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,
)...