hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : JavaScript Image Rollovers
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

JavaScript Image Rollovers

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 10-02-2002, 08:30 AM
Joshua44 Joshua44 is offline
WHT Addict
 
Join Date: Feb 2002
Posts: 109
Question

JavaScript Image Rollovers


ARG!! For some reason this script isn't working; if you roll the mouse over the "Tongue Twisters" image and all the images above it, it says "Object doesn't support this property or method."
Tongue Twisters is on line 307.

I attached the file.. Please help!!
Attached Files
File Type: txt menu.txt (11.2 KB, 50 views)

Reply With Quote


Sponsored Links
  #2  
Old 10-02-2002, 09:06 AM
Chas Chas is offline
WHT Addict
 
Join Date: Apr 2001
Location: California
Posts: 131
Hi Joshua44 ,

You should rethink your code. There is a lot of repetition that doesn't need to be there. Try something like this:

Code:
<script>
//mouseOver on & off images
img22off = new Image(); img22off.src = "images/2-2-off.jpg";
img22on  = new Image(); img22on.src  = "images/2-2-on.jpg";

img24off = new Image(); img24off.src = "images/2-4-off.jpg";
img24on  = new Image(); img24on.src  = "images/2-4-on.jpg";

// add the rest of your images here.  Keep the same 
// naming convention going.

//mouseOver image swap
function over(img) {
  document[img].src = eval(img + "on.src");
}

//mouseOut image swap
function off(img) {
  document[img].src = eval(img + "off.src");
}
</script>
Your html should look like this:

Code:
<a href="ps/" 
  onMouseover="over('img22');"
  onMouseout="off('img22');">
<img src="/images/2-2-off.jpg" name="img22" border="0" width="108" height="58"></a>
The important part of the code is to keep the naming convention for the image objects. The on and off part of the name is what you need to worry about. This way you only need one function for all of your overs and offs instead of a separate function for each rollover like you have.

Let me know if you need me to explain the code better.

Regards,
Charlie

Reply With Quote
  #3  
Old 10-02-2002, 09:19 AM
Joshua44 Joshua44 is offline
WHT Addict
 
Join Date: Feb 2002
Posts: 109
Thanks soooooooooooooooooooooooo much, everything's fine now!
I still can't figure out what was wrong, but this is a better code... thanks!!

__________________
www.jportalhome.com

Reply With Quote
Sponsored Links
Reply

Related posts from TheWhir.com
Title Type Date Posted
Facebook's Recently Acquired Mobile App Platform Parse Launches Web Hosting for Developers Web Hosting News 2013-05-08 10:49:17
Customer Feature: How EdgeCast Delivers One Billion Imgur Images Each Day Web Hosting News 2012-05-31 12:22:36
Software Developer Softaculous Launches Softaculous Auto Installer Version 3.8 Web Hosting News 2011-11-25 15:34:49
Hurricane Electric Offers Online Courses for Developers and Designers Web Hosting News 2011-11-14 21:51:44
Web Host SoftLayer Launches Public Image Repository for Cloud Templates Web Hosting News 2011-06-08 14:56:19


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?