Mourning the loss of our friend, WhitPhil.
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 audio blue screen boot bsod connection crash dell desktop driver drivers dvd email error excel excel 2003 firefox hard drive hardware internet keyboard laptop malware monitor motherboard network networking outlook problem processor ram recovery router safe mode screen slow sound spyware tdlwsp.dll trojan upgrade video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Can Javascript do this?

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
tempusfugitive's Avatar
Computer Specs
Member with 35 posts.
 
Join Date: Jun 2007
Experience: Intermediate
25-Aug-2009, 05: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
Distinguished Member with 3,519 posts.
 
Join Date: Oct 2006
25-Aug-2009, 08:17 PM #2
Yes, post your code.
tempusfugitive's Avatar
Computer Specs
Member with 35 posts.
 
Join Date: Jun 2007
Experience: Intermediate
25-Aug-2009, 09: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
Distinguished Member with 3,519 posts.
 
Join Date: Oct 2006
26-Aug-2009, 02: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
Closed Thread Bookmark and Share

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.

Smart Search

Find your solution!



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


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 04:57 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.