Click to See Complete Forum and Search --> : Failing to Apply attributes


7Priest7
June 27th, 2007, 01:22 PM
<script type="text/javascript">
var handImage=new Array("across.gif","down.gif")
var IE = document.attachEvent ? true:false;
var DOM = document.addEventListener ? true: false;
var currentX=0,currentY=0;
var currentCell,currentColor="white",across=true,keyNum;

function init() {
var currentCell=document.getElementById('grid00');
currentColor="yellow";
currentCell.style.backgroundcolor=currentColor;
document.onkeydown=getKey;
writeClues();
}

function getKey(e)
{
if (IE) keyNum = event.keyCode;
else if (DOM) keyNum = e.keyCode;
if(keyNum==32) { toggleDirection(); }
else if (keyNum ==37||keyNum==38||keyNum==39||keyNum==40) { moveCursor(); }
else { writeGuess(); }
}

function toggleDirection()
{
if(across==true) { across = false;
document.images[1].src=handImage[1]; }
else if(across==false) { across = true;
document.images[1].src=handImage[0]; }
}
</script>


It is failing to apply the attributes like the yellow background color or the new image...

Any/All help appreciated

Please and Thank You

Alex

PeejAvery
June 27th, 2007, 01:28 PM
Change...
currentColor="yellow";
currentCell.style.backgroundcolor=currentColor;
To...
currentCell.style.background = '#ffff00';

7Priest7
June 27th, 2007, 01:56 PM
Thank You
Amazing how simple...

How bout the image that is failing to apply

function getKey(e)
{
if (IE) keyNum = event.keyCode;
else if (DOM) keyNum = e.keyCode;
if(keyNum==32) { toggleDirection(); }
else if (keyNum ==37||keyNum==38||keyNum==39||keyNum==40) { moveCursor(); }
else { writeGuess(); }
}

function toggleDirection()
{
if(across==true) { across = false;
document.images[1].src="down.gif"; }
else if(across==false) { across = true;
document.images[1].src="across.gif"; }
}

PeejAvery
June 27th, 2007, 02:14 PM
How bout the image that is failing to apply
Well, that could be a number of things.

First, where have you declared the variable across? If that has not been declared, then it won't fire because it won't find a value. Here is a cleaner version of your code.

var across = true;
function toggleDirection(){
if(across){
across = false;
document.images[1].src = "down.gif";
}
else{
across = true;
document.images[1].src = "across.gif";
}
}

7Priest7
June 27th, 2007, 02:19 PM
You're a super brain...
I don't see much/any diffrence...
I guess your if else is better than mine...
I did declare the across so it wasent that...
I think the browser wasent accepting my if else statement

Much Thanks
Alex

PeejAvery
June 27th, 2007, 02:37 PM
I think the browser wasent accepting my if else statement
Two things.

1. It is called else if, not if else.

2. In order to have else if, you must have a minimum of three items. If you only have two, then you would...
if(condition){action if true;}
else{action if false;}