There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus batch bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop lcd malware memory modem monitor motherboard network printer problem ram registry router slow software sound toshiba trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Can Javascript do this?

Reply  
Thread Tools
tempusfugitive's Avatar
Computer Specs
Member with 59 posts.
 
Join Date: Jun 2007
Experience: Intermediate
25-Aug-2009, 06:04 PM #1
Question Can Javascript do this?
I have a page element for which onMouseOver and onMouseOut call the same function. However, I want the function to do something different depending on which of these two events initiated it. Does Javascript include some sort of functionality to detect which event has triggered something?

I know that I can just make two versions of the function, or pass some sort of argument to differentiate between events, but I'm looking for something more elegant.

Thanks.
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,637 posts.
 
Join Date: Oct 2006
25-Aug-2009, 09:17 PM #2
Yes, post your code.
tempusfugitive's Avatar
Computer Specs
Member with 59 posts.
 
Join Date: Jun 2007
Experience: Intermediate
25-Aug-2009, 10:12 PM #3
The elements are table data cells:

<td bgcolor="darkblue" id="glossary"
onMouseOver="resourcesMenu(id)"
onMouseOut="resourcesMenu(id)">
Glossary
</td>

and the function resourcesMenu() should combine the functionality of the following (previously used) two functions to change the cell text onmouseover and change it back onmouseout. I am passing in an id because I want to use resourcesMenu() for different table cells:

function glossaryMouseOver()
{
document.getElementById("glossaryCell").innerHTML='Site terms';
}

function glossaryMouseOut()
{
document.getElementById("glossaryCell").innerHTML='Glossary';
}

My plan was to have something like this:

function resourcesMenu(whichCell)
{
if(whichCell.onMouseOver)
change text;

if(whichCell.onMouseOut)
change text back;
}
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,637 posts.
 
Join Date: Oct 2006
26-Aug-2009, 03:38 AM #4
HTML Code:
<td bgcolor="darkblue" id="glossary"
onMouseOver="resourcesMenu(id, event || window.event)"
onMouseOut="resourcesMenu(id, event || window.event)">
Glossary
</td> 
Code:
function resourcesMenu(whichCell, e)
{
if(e.type = 'mouseover')
change text;
else if(e.type = 'mouseout')
change text back;
}

not tested
Reply

Tags
events, function, javascript

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:59 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.