By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,599 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,599 IT Pros & Developers. It's quick & easy.

Multiple handlers for a given function

P: n/a
Is there a shorthand way to assign the same actions to multiple handlers
? I know I can just just do:
onBlur='myFunction()';onClick='myFunction()'

I'm just looking to save some keystrokes. I actually have this issue now
and it involves a couple of functions with long parameter lists.
TIA
Sep 8 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Lorenzo Thurman said the following on 9/8/2006 2:00 PM:
Is there a shorthand way to assign the same actions to multiple handlers
? I know I can just just do:
onBlur='myFunction()';onClick='myFunction()'

I'm just looking to save some keystrokes. I actually have this issue now
and it involves a couple of functions with long parameter lists.
<element id="someID" onclick="something('longParameterList')">

window.onload=duplicateThem()

function duplicateThem(){
document.getElementById('someID').onblur=document. getElementById('someID').onmouseover
}

How do you blur something without clicking it though?
The only way to do that is by setting focus via script and if you are
doing that, you simply call the same function.

Or you can write a wrapper function:

function dummyFunction(objectCallingMe){
someOtherFunction('All my parameters here',objectCallingMe)
}

objectCallingMe is in case you are passing "this" as a parameter.

onclick="dummyFunction()" onblur="dummyFunction()"

Of all the possibilities, I would combine the two, it allows less room
for typo errors.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 8 '06 #2

P: n/a
Randy Webb said the following on 9/8/2006 3:13 PM:
Lorenzo Thurman said the following on 9/8/2006 2:00 PM:
>Is there a shorthand way to assign the same actions to multiple
handlers ? I know I can just just do:
onBlur='myFunction()';onClick='myFunction()'

I'm just looking to save some keystrokes. I actually have this issue
now and it involves a couple of functions with long parameter lists.

<element id="someID" onclick="something('longParameterList')">

window.onload=duplicateThem()
That should be:

window.onload=duplicateThem;

without the ()

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Sep 8 '06 #3

P: n/a
Randy Webb wrote:
Lorenzo Thurman said the following on 9/8/2006 2:00 PM:
>Is there a shorthand way to assign the same actions to multiple
handlers ? I know I can just just do:
onBlur='myFunction()';onClick='myFunction()'

I'm just looking to save some keystrokes. I actually have this issue
now and it involves a couple of functions with long parameter lists.

<element id="someID" onclick="something('longParameterList')">

window.onload=duplicateThem()

function duplicateThem(){
document.getElementById('someID').onblur=document. getElementById('someID').onmouseover

}

How do you blur something without clicking it though?
The only way to do that is by setting focus via script and if you are
doing that, you simply call the same function.

Or you can write a wrapper function:

function dummyFunction(objectCallingMe){
someOtherFunction('All my parameters here',objectCallingMe)
}

objectCallingMe is in case you are passing "this" as a parameter.

onclick="dummyFunction()" onblur="dummyFunction()"

Of all the possibilities, I would combine the two, it allows less room
for typo errors.
Thanks, I'll go with combining them.
Sep 8 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.