By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,060 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

Rollover Button script not working

P: n/a
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_homew...l_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/)

Feb 3 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> 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.

Feb 3 '06 #2

P: n/a

old_school_skater wrote:
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_homew...l_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:

<script type = "text/javascript">
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;

Feb 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.