User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 375,195 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,163 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1467 | Replies: 7
Reply
Join Date: Sep 2005
Location: St. Louis
Posts: 139
Reputation: kahaj is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
kahaj kahaj is offline Offline
Junior Poster

Question Multiple Mouseover Events

  #1  
Dec 18th, 2007
How do I have multiple mouseover events at the same time? Here's what I have so far.

<a href="assets/Ads/agapeCreations.pdf" />
  <img src="assets/Ads/agapeCreationsNorm.jpg" alt="Agape Creations Photography" 
  onmouseover="this.src='assets/Ads/agapeCreationsMouseOver.jpg' 'self.status='Agape Creations Photography';return true" 
  onmouseout="this.src='assets/Ads/agapeCreationsNorm.jpg';return true" 
  width="725" height="80" border="0" border=0 /></a><br />

I have the images swapping fine, but the self.status isn't working.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,732
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 323
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Multiple Mouseover Events

  #2  
Dec 18th, 2007
Inline javascript code is really not recommended.

Firstly it is difficult to maintain since it clutters the already cluttered markup. Secondly, it absolutely lacks the separation of logic and presentation, something which you should definitely try to achieve always. Thirdly changing the logic may require changing the code at multiple locations. Having the functionality packed up or encapsulated inside a single function is much recommended.

Attach a listener to your onmouseover event handler to do the required job for you and encapsulate your image swapping logic in that listener.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Sep 2005
Location: St. Louis
Posts: 139
Reputation: kahaj is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
kahaj kahaj is offline Offline
Junior Poster

Re: Multiple Mouseover Events

  #3  
Dec 18th, 2007
Hmm. I'll have to do some looking up on listeners. I've not heard of them before. I'm obviously quite new to JavaScript though.

Thanks!
Reply With Quote  
Join Date: Dec 2007
Location: Russia
Posts: 11
Reputation: adorosh is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
adorosh adorosh is offline Offline
Newbie Poster

Re: Multiple Mouseover Events

  #4  
Dec 22nd, 2007
try window.status='' instead
Reply With Quote  
Join Date: Sep 2005
Location: St. Louis
Posts: 139
Reputation: kahaj is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
kahaj kahaj is offline Offline
Junior Poster

Re: Multiple Mouseover Events

  #5  
Jan 8th, 2008
From what I've been able to see, listeners aren't supported thoroughly yet. Are they a good universal thing to use right now?

Also, I've changed what I'm trying to accomplish. I'm trying to get the images to swap out when the mouse is rolled over. I'd really rather not have to use a mousedown. But this mouseover doesn't seem to be working for me:

  <a href="assets/Ads/agapeCreations.pdf"
  onmouseover="this.src='assets/Ads/agapeCreationsMouseOver.jpg';return true"
  onmouseout="this.src='assets/Ads/agapeCreationsNorm.jpg';return true">
  <img src="assets/Ads/agapeCreationsNorm.jpg" alt="Agape Creations Photography" width="725" height="80" border="0"></a>
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,732
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 323
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Multiple Mouseover Events

  #6  
Jan 8th, 2008
> From what I've been able to see, listeners aren't supported thoroughly yet. Are they a
> good universal thing to use right now?
There are two ways of attaching a listener to an event handler of an HTML element.

One is to directly assign a function to that event handler which would then act as a listener. An example would be:
  1. window.onload = function() {
  2. initEvents();
  3. initGlobals();
  4. }
The disadvantage here is that you can't attach multiple event handlers to the listener in a clean and simple manner since assigning another listener would result in the previous one being erased.

Another way is to use the functions provided by the event object such as attachEvent[IE only] or addEventListener [Gecko based browsers]. So, in a sense you are right in saying that the listener function is not supported by non-Gecko browsers like IE. Here I would be presenting a simple wrapper which would attach events in a almost transparent manner and should work on almost all browsers out there.
/**
 * Attaches a event listener
 * @author sos
 * @param el {HTMLElement} The element to which you would attach this listener
 * @param ev {String} The event name (eg. click)
 * @param fn {Function} The event listener function
 */
function addEvent(el, ev, fn) {
    if(el.addEventListener) {
        el.addEventListener(ev, fn, false);
    }
    else {
        el.attachEvent('on' + ev, fn);
    }
}

And oh, BTW, you don't need Javascript to get the rollover effect. It can be done very well achieved using a pure CSS solution.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Sep 2005
Location: St. Louis
Posts: 139
Reputation: kahaj is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
kahaj kahaj is offline Offline
Junior Poster

Re: Multiple Mouseover Events

  #7  
Jan 10th, 2008
Okay, but for curiosity's sake, if I were to use JavaScript for the rollover effect, would the above be correct?
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,732
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 323
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Multiple Mouseover Events

  #8  
Jan 11th, 2008
The problem is that you are trying to access the src property of the anchor (<a>) element instead of the image element. Move the mouseover and mouseout declarations from the <a> tag to the <img> tag and it should work out to be fine. But then again, it's not the best of methods, you have been warned.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 2:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC