beennn Posted July 21, 2011 Share Posted July 21, 2011 <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 More sharing options...
Ingolme Posted July 21, 2011 Share Posted July 21, 2011 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 More sharing options...
jeffman Posted July 21, 2011 Share Posted July 21, 2011 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 More sharing options...
beennn Posted July 21, 2011 Author Share Posted July 21, 2011 Is there any way around that?EDIT:Thank you Link to comment Share on other sites More sharing options...
jeffman Posted July 21, 2011 Share Posted July 21, 2011 Make sure you notice my post, which came in just before your question. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.