Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

You were a huge help last time. Javascript buttons 1

Status
Not open for further replies.

isilkin

Technical User
Feb 12, 2008
27
US
Hello, Everyone again!
Last time you guys were a huge help.
I am running into a problem. The buttons on my site that are controled via javascript for some reason cauing all other hyperlinked images to work incorrectly.
here is the example (just hove over adobe image)
I will attache my script file. Hopefully someone knows why it is happening.

Thank you so much again.
If attachment is not working copy and paste this in your browser
 
I'd start by doing a syntax check on the HTML, as :

Code:
<td><a href="[URL unfurl="true"]www.adobe.com"><img[/URL] src="images/adobe-reader.jpg"</a></td>

should be :

Code:
<td><a href="[b]http://[/b][URL unfurl="true"]www.adobe.com"><img[/URL] src="images/adobe-reader.jpg"[b]>[/b]</a></td>

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
I just fixed that but the problem is still there.
I know for sure it is in the javascript because if I disable the script than the link work propertly.
Thank you angain for your reply
 
It's probably these two lines in your 'setupRollover' function:

Code:
thisImage.overImage.src = "images/" + thisImage.id + "_on.png";

thisImage.clickImage.src = "images/" + thisImage.id + "_click.png";

Quite clearly, the image doesn't have an ID, so its SRC is not being set to what you expect.

So, either give it an ID to make it load the image you expect, or modify your code accordingly.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thank you again for your input. I have tried giving an image a unique ID but it didn't change anything. Also, i think the file should be named something_on.png to be affected by the javascript. I thought if it is named anything else it would not be affected.

How do I stop the rollover code from running on images where I don't wish a rollover to take place?

Huge thanks again
 
Ok, guys I have narrowed it down to these 4 lines of code. Because if I delete this code everything works. I don't want to rewrite the whole code. Can anyone think of a workaround?

thisImage.overImage = new Image();
thisImage.overImage.src = "images/" + thisImage.id + "_on.png";
thisImage.onmouseover = rollOver;
thisImage.style.borderWidth = '0px';

I even tried placing the top image in a different folder so the code won't affect it, but it didn't help.

 
 http://isilkin.com/repair/script.js
There are many ways to stop the rollover code from affecting items you do not want it to.

One way would be to only attach the rollover code to items with a certain class... or, you could flip that and not attach the code to anything with a certain class. It really depends on whether more items will need rollover code, or less.

For example, to exclude certain images, give them a class of "noRollover", then add this line at the top of your "setupRollover" function:

Code:
if (thisImage.className == 'noRollover') return;

Like I said, the decision as to whether you do it by including or excluding images should be based around how many images would need this.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
You are the bomb it fixed the issue. Thank you, thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top