Page 1 of 1

Why does this return FALSE???? ARRRGGGHH

Posted: Wed Nov 26, 2003 9:13 am
by JayBird
here my javascript function

Code: Select all

<SCRIPT>
				function showInfo(layerName)
				&#123;
				var layerName;
				
					if(layerName == "Engines")
					&#123;
						document.write('TRUE');
					&#125; else &#123;
						document.write('FALSE');
					&#125;
				&#125;
				</SCRIPT>
Here is the link that calls it

Code: Select all

<a href="javascript:showInfo(Engines);">Latest John Deere PowerTech Engines</a>
Why does it return FALSE??

Mark

Posted: Wed Nov 26, 2003 9:19 am
by Weirdan
Because you have redefined the variable:

Code: Select all

var layerName;
Remove this line, it should solve your problem.
Just my guess...

Posted: Wed Nov 26, 2003 9:24 am
by JayBird
nope, still returns false
I think it is something to do with layerName being an object for some reason.

I really don't know enough about JS tho to figure it out

Mark

Posted: Wed Nov 26, 2003 9:27 am
by Weirdan

Code: Select all

<SCRIPT> 
    function showInfo(layerName) 
    &#123; 
        if(layerName == "Engines") 
        &#123; 
             document.write('TRUE'); 
        &#125; else &#123; 
             document.write('FALSE'); 
        &#125; 
    &#125; 
</SCRIPT> 
	
<a href="javascript:showInfo('Engines');">Latest John Deere PowerTech Engines</a>
Notice the quotes in function call.

Posted: Wed Nov 26, 2003 9:33 am
by JayBird
Okay, i c

so how do i use the variable layerName when referencing an object

I wanna change the content on the DIV called "Engines". You would normally do it like this

Code: Select all

Engines.innerHTML = "It worked";
but, there will be different layers on the page, so i wanna replace Engines with a variable, i thought this would work, but doesm't

Code: Select all

layerName.innerHTML = "It worked";
Mark

Posted: Wed Nov 26, 2003 9:40 am
by Weirdan
If you want to pass string to the function:

Code: Select all

<script type='text/javascript' language='JavaScript'> 
    function showInfo(layerName) 
    &#123;
       var q = document.getElementById(layerName);
       q.innerHTML="It works!";
    &#125;
</script>
<a href="javascript:showInfo('Engines');">Latest John Deere PowerTech Engines</a>
<div id='Engines'></div>

Posted: Wed Nov 26, 2003 9:43 am
by JayBird
thank f*ck for that, been tearing my hair out with this.

I've decided i don't like JavaScript :)

Cheerz buddy

Mark