View Full Version : Help with a script please!

12-21-2002, 03:34 PM
This is probably something really simple I'm missing out as I'm hardly a javascript expert but i'm having difficulties creating a script on my webpage.

Its a real simple script, I am designing a navigation menu and i want the background of each item on the menu to change color onmouseover. I've tried doing this in two ways:

1) using an onmouseover in the <td> tag of my menu table:

<td onmouseover="javascript:this.bgcolor=colors[0]>

colors is an array I have set within the head tags of my webpage, I have also tried putting in a color and hex value and still the background will not change color. This should be really simple i've used it before and if only i could get to a computer at colllege i could work it out!

2) I have used <span> tags and used a script to try and alter the background-color in style. When i do this i keep getting syntax errors where i use the '-' symbol in my script.

Can any give me any idea of where i'm goin wrong? This is driving me mad! If there is a better or easier way of doin this then I would be grateful for some ideas. I am using IE6 and ultimatley will be enhancing the script to include a color fade onmouseover but for now I'm just stuck with the simple begginings!

Any help will be greatly appreciated

12-21-2002, 04:34 PM
this should do the job, but...
<td onmouseover="javascript:this.style.background='blue'>
it will be more difficcult to get it to do it with that color array, try this

function test(loc) {
loc.style.background = colors[0];
<td onmouseover="javascript:test(this)">

12-21-2002, 05:01 PM
Thanks a lot mate! the second bit works a treat!

Would the easiest way 2 make a fade be to use setTimeout and make the script go through all the colours in my array?