Multiple handlers for a given function

  • Thread starter Lorenzo Thurman
  • Start date
L

Lorenzo Thurman

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
 
R

Randy Webb

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.
 
R

Randy Webb

Randy Webb said the following on 9/8/2006 3:13 PM:
Lorenzo Thurman said the following on 9/8/2006 2:00 PM:

<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
 
L

Lorenzo Thurman

Randy said:
Lorenzo Thurman said the following on 9/8/2006 2:00 PM:

<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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top