JavaScript and client side scripting.
Moderator: General Moderators
-
JayBird
- Admin
- Posts: 4524
- Joined: Wed Aug 13, 2003 7:02 am
- Location: York, UK
-
Contact:
Post
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
-
Weirdan
- Moderator
- Posts: 5978
- Joined: Mon Nov 03, 2003 6:13 pm
- Location: Odessa, Ukraine
Post
by Weirdan »
Because you have redefined the variable:
Remove this line, it should solve your problem.
Just my guess...
-
JayBird
- Admin
- Posts: 4524
- Joined: Wed Aug 13, 2003 7:02 am
- Location: York, UK
-
Contact:
Post
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
-
Weirdan
- Moderator
- Posts: 5978
- Joined: Mon Nov 03, 2003 6:13 pm
- Location: Odessa, Ukraine
Post
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.
-
JayBird
- Admin
- Posts: 4524
- Joined: Wed Aug 13, 2003 7:02 am
- Location: York, UK
-
Contact:
Post
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
-
Weirdan
- Moderator
- Posts: 5978
- Joined: Mon Nov 03, 2003 6:13 pm
- Location: Odessa, Ukraine
Post
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>
-
JayBird
- Admin
- Posts: 4524
- Joined: Wed Aug 13, 2003 7:02 am
- Location: York, UK
-
Contact:
Post
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