Darkmatter5 Posted November 13, 2008 Share Posted November 13, 2008 Here's my code: <style type="text/css"> #site_admin, #user_admin, #news_man { display: none; } </style> <script type="text/javascript"> function toggle(thediv) { document.getElementById("site_admin").style.display = "none"; document.getElementById("user_admin").style.display = "none"; document.getElementById("news_man").style.display = "none"; document.getElementById(thediv).style.display = "block"; } </script> <a href="" onClick="toggle('site_admin');" />Site Administration</a> | <a href="" onClick="toggle('user_admin');" />User Administration</a> | <a href="" onClick="toggle('news_man');" />News Manager</a> <input type="radio" name="toggledivs" onclick="toggle('site_admin');" />Site Admin<br> <input type="radio" name="toggledivs" onclick="toggle('user_admin');" />User Admin<br> <input type="radio" name="toggledivs" onclick="toggle('news_man');" />News Man<br> Now the radio buttons work fine, but the href's don't. They'll display the div if clicked, but after a second it'll disappear again, how do I make it say there until another link is clicked? Quote Link to comment https://forums.phpfreaks.com/topic/132574-hiding-and-displaying-div-help/ Share on other sites More sharing options...
premiso Posted November 13, 2008 Share Posted November 13, 2008 How is this related to PHP? Should be in the Javascript form.... Quote Link to comment https://forums.phpfreaks.com/topic/132574-hiding-and-displaying-div-help/#findComment-689365 Share on other sites More sharing options...
perezf Posted November 19, 2008 Share Posted November 19, 2008 I created a version of the hide and show, let me know if this helps <html> <head> <title>Display/Hide Content</title> <style type="text/css"> #ContentToDisplay { display: none; } </style> <script type="text/javascript" language="Javascript"> function showContent(idAlternate) { if(document.getElementById(idAlternate).style.display == 'block') { document.getElementById(idAlternate).style.display = 'none'; } else if(document.getElementById(idAlternate).style.display = 'none') { document.getElementById(idAlternate).style.display = 'block'; } } </script> </head> <body> <a href="#" onclick="javascript:showContent('ContentToDisplay');">Show/Hide Div</a> <div id="ContentToDisplay"> <p>This is the Hidden Content</p> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/132574-hiding-and-displaying-div-help/#findComment-693189 Share on other sites More sharing options...
premiso Posted November 19, 2008 Share Posted November 19, 2008 <script type="text/javascript" language="Javascript"> function showContent(idAlternate) { var hideShow = document.getElementById(idAlternate); if(hideShow.style.display == 'block') { hideShow.style.display = 'none'; } else if(hideShow.style.display == 'none') { // added another = here it should be == hideShow.style.display = 'block'; } } </script> Added an extra = to the elseif and create a var to house the document element, this way you do not have to keep calling that, just the variable. I have not clue if the below would break it but I never use javascript: <a href="#" onclick="showContent('ContentToDisplay'); return false;">Show/Hide Div</a> That should work, untested but yea. I would suggest getting FireFox as it has a "Error Console" that will post you all the javascript errors, if there are any, your page has. Great for debugging javascript. Quote Link to comment https://forums.phpfreaks.com/topic/132574-hiding-and-displaying-div-help/#findComment-693490 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.