Forum Moderators: open

Message Too Old, No Replies

Javascript function document.writes nothing.

No output is given

         

Igau

12:38 am on Nov 14, 2003 (gmt 0)

10+ Year Member



Hi... I'm being a total loser and trying to "fix" my post count display on a forum), I have the appropriate access to the templates etc.

I cant be bothered to edit the actual PHP source... and it seems that using PHP in the templates does nothing, so I'm testing some javascript that can easily be used to do what I want. Only problem is that when run...nothing is document.written, so to speak.

I'm not good at Javascript at all, so can someone kindly tell me where I've gone wrong here?

<script type="text/javascript">

function harhar(name,posts) {

if(name == "Imleet") {return 1337;}
else {return posts;}

}

document.write("Posts: ");
document.write(harhar(test,30));

</script>

<noscript>
Posts: 30
</noscript>

DrDoc

1:30 am on Nov 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"test" is not defined. "test" without quotes is interpreted as a variable.

Putting quotes (single or double) makes it work :)

<script type="text/javascript">

function harhar(name,posts) {

if(name == "Imleet") {return 1337;}
else {return posts;}

}

document.write("Posts: ");
document.write(harhar('test',30));

</script>

Igau

1:45 am on Nov 14, 2003 (gmt 0)

10+ Year Member



......oops, my bad. You're right, thanks :)