Jump to content

Could someone please point out what im doing wrong


beennn

Recommended Posts

<script type="text/javascript"> var show_friends = false;</script><a href="#" onClick="java script:show_friends = true">Friends</a><script type="text/javascript"> if(show_friends == true){ document.write("Hello");} </script>

Link to comment
Share on other sites

The Javascript only runs once and it all runs as soon as it's loaded. When you click the link you're setting show_friends to true, but there's no script doing anything with that variable anymore.

Link to comment
Share on other sites

You have provided no mechanism to trigger the code in your second script. What you need is a function you can execute. This is one way to do it:

<a href="#" onclick="show_friends(true)">Friends</a><script type="text/javascript">   function show_friends (val) {	  if (val == true){		 document.write("Hello");	  }   }</script>

Be aware that using document.write this way will replace the current document with a new one.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...