Forum Moderators: open

Message Too Old, No Replies

invalid assignment left-hand side

         

LouiseMarie

12:19 pm on Mar 15, 2010 (gmt 0)

10+ Year Member



Hi,

I'm fairly new to javascript and I don't know what to change to fix this error:

mozilla javascript console said: "invalid assignment left-hand side"

heres my code:
Script in the head tag:-
<script type="text/javascript" language="javascript">
function fcnAlterColour(ID, Colour){
document.getElementById(ID).style.background-Color = 'Colour';
}
</script>

call function in html:
<td onclick="fcnAlterColour('findusimages', '#000000')"></td>

td to change background colour in html:
<td id="findusimages"></td>


thanks in advance

PCInk

12:26 pm on Mar 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



"background-Color"

There is no dashes in JS because it thinks it is a subtract sign. That's what is confusing the JS.

I haven't looked it up, but should it be backgroundColor?

LouiseMarie

2:35 pm on Mar 15, 2010 (gmt 0)

10+ Year Member



thank you for help, much appreciated. It was the dash that was causing the problem but I also needed to remove the quote marks around the Colour declaration.

So for the benefit of other users here is the workinf script:

<script type="text/javascript" language="javascript">
function fcnAlterColour(ID, Colour){
document.getElementById(ID).style.backgroundColor =Colour;
}
</script>