Rollover Button script not working

  • Thread starter old_school_skater
  • Start date
O

old_school_skater

I'm new to html and Javascript and have been given an assignment from a
friend to get me up to speed. I've followed instructions from Thomas
A. Powells book HTML THE COMPLETE REFERENCE 3rd Edition on how to code
basic Rollover Buttons using javascript but can't get them to work at
all. This is my first experince coding with Javascript.

Please see http://www.skatopia.co.nz/Phil_homework_2/phil_answer2.html

The code is only for the first button at this point (ie the INITIATE
button on the navigation near the top of the page) I wanted to
understand it before applying the code to the other buttons.

ps - In an effort to not be influenced by the code from WYSIWYG editors
I wrote the code in Notepad. I've been validating the code at
http://validator.w3.org/, and used Dave Raggetts TIDY ONLINE to clean
up my code (http://valet.htmlhelp.com/tidy/)
 
M

Morgan

The code is only for the first button at this point (ie the INITIATE
button on the navigation near the top of the page) I wanted to
understand it before applying the code to the other buttons.

I don't see any images called "buttonon" in your images directory.
 
W

web.dev

old_school_skater said:
I'm new to html and Javascript and have been given an assignment from a
friend to get me up to speed. I've followed instructions from Thomas
A. Powells book HTML THE COMPLETE REFERENCE 3rd Edition on how to code
basic Rollover Buttons using javascript but can't get them to work at
all. This is my first experince coding with Javascript.

Please see http://www.skatopia.co.nz/Phil_homework_2/phil_answer2.html

The code is only for the first button at this point (ie the INITIATE
button on the navigation near the top of the page) I wanted to
understand it before applying the code to the other buttons.

Next time be more descriptive about what "doesn't work", and it would
be helpful to post the script to diagnose.

This is the script you have:
<script type="text/javascript" language="JavaScript">

The language attribute is deprecated, just stay with the type
attribute:

buttonoff = new Image();
buttonoff.src = "buttonoff.gif";
buttonon = new Image();
buttonon.src = "buttonon.gif";

These are being used as global variables. It's usually a good idea to
have them declared them somewhere.

var buttonoff, buttonon;
document[imageName].src = eval(imageName+"on.src");
document[imageName].src = eval(imageName+"off.src");

Did the book tell you to use the eval function? The eval function is
generally not necessary. Also, you are not using the images
collection. Instead do the following:

document.images[imageName].src = buttonon.src;
document.images[imageName].src = buttonoff.src;
 

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