Northern Flame Posted December 3, 2007 Share Posted December 3, 2007 I hardly program in Javascript and when I do its simple stuff, but I am stuck on something. I want to have a few links where if the user click them, something is displayed in a certain div. Heres a simple sample that I was practicing with so that you guys can better understand what I am trying to do. Can anyone help me make this work? <script type="text/javascript"> function secondDiv(){ document.write('This is the default text....'); } function numberOne(){ function secondDiv(){ document.write('Number One'); } } function numberTwo(){ function secondDiv(){ document.write('Number Two'); } } </script> <div style="background-color:#CC0000;"> <a onClick="numberOne()" href="javascript:void(0)">Number One</a><br> <a onClick="numberTwo()" href="javascript:void(0)">Number Two</a><br> </div> <div> <script type="text/javascript"> secondDiv(); </script> </div> it displays "This is the default text...." but the text doesnt change, maybe I am doing this wrong, am I suppose to do it another way other than changing the function that is being displayed? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 3, 2007 Share Posted December 3, 2007 don't use document.write in a function; I have never seen that turn out good. do it like this: <script type="text/javascript"> function numberOne() { document.getElementById('content').innerHTML='Number 1'; } function numberTwo() { document.getElementById('content').innerHTML='Number 2'; } </script> <div style="background-color:#CC0000;"> <a onClick="numberOne()" href="javascript:void(0)">Number One</a><br> <a onClick="numberTwo()" href="javascript:void(0)">Number Two</a><br> </div> <div> <span id="content"> This is the default text.... </span> </div> Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted December 4, 2007 Author Share Posted December 4, 2007 Wow Thanks! That was actually easier that I thought it would be and thanks for the tip about the document.write Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.