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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with simple rollover script 1

Status
Not open for further replies.

Foamcow

Programmer
Nov 14, 2002
6,092
GB
Hi,

I'm not big on Javascript, it's kind of on the periphary of what I do but I've had need to knock up a simple rollover script for a current job.
It doesn't need to be particularly portable but I would like to easily be able to add/remove buttons without messing with the javascript. Apologies in advance for any horrible coding faux pas I've made :)

Code:
	window.onload=function(){
		var nav = document.getElementById('nav');
		
		var buttons = nav.getElementsByTagName('IMG');

		for(var i=0; i<buttons.length; i++){
			buttons[i].onmouseover = function(){
				var original = this.getAttribute('src');
				var original = original.split('/');
				this.setAttribute('src','images/' + 'on_' + original[1]);
			}
			
			buttons[i].onmouseout = function(){
				var original = this.getAttribute('src');
				var original = original.split('_');
				this.setAttribute('src','images/btn_' + original[2]);
			}
		}
	
	}

Now to the problem...
The script is meant to swap out a few images by altering the src attribute. More specifically changing the src from say,

btn_about.png to on_btn_about.png

This seems to work fine in Firefox and Safari but doesn't work in IE (windows).

When I rollover one of the buttons, the src changes but it just changes to "on_" rather than "on_btn_about.png"


Any ideas why?

<honk>*:O)</honk>
Foamcow Heavy Industries - Web site design in Cheltenham and Gloucester
Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire
 
glad I could be of help [smile]

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top