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)
{
var layerName;
if(layerName == "Engines")
{
document.write('TRUE');
} else {
document.write('FALSE');
}
}
</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:
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)
{
if(layerName == "Engines")
{
document.write('TRUE');
} else {
document.write('FALSE');
}
}
</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
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)
{
var q = document.getElementById(layerName);
q.innerHTML="It works!";
}
</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