BK201 Posted June 22, 2012 Share Posted June 22, 2012 Argh! JS haha. I'm trying to toggle a input box on and off by click. It toggles on, but then it does not toggle back off. Any help is greatly appreciated. function show() { var character_node = document.getElementById("CC"); var name_node = document.getElementById("cn_label"); if (character_node && name_node) { name_node.hidden = ""; } else if (character_node == true && name_node == false) { name_node.hidden = "1"; } } <form name = "Character Creation" action = "scripts/character_creation.php" method = "POST"> <p onClick="show();" id="CC">Create Character</p> <label hidden="1" id="cn_label">Character Name<input type="text" name="name"></label> </form> Quote Link to comment https://forums.phpfreaks.com/topic/264629-toggle-hidden/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 23, 2012 Share Posted June 23, 2012 Use jQuery to ease your scripting. the best way to do with jQuery is <style> #cn_label { display:none; } </style> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function(){ $('#CC').click(function() { $('#cn_label').toggle('slow', function() { }); }); </script> <form name = "Character Creation" action = "scripts/character_creation.php" method = "POST"> <p id="CC">Create Character</p> <label id="cn_label">Character Name<input type="text" name="name"></label> </form> Quote Link to comment https://forums.phpfreaks.com/topic/264629-toggle-hidden/#findComment-1356382 Share on other sites More sharing options...
BK201 Posted June 23, 2012 Author Share Posted June 23, 2012 Thanks mate, I'm trying to get a better grasp on JS before I move to JQuery. Maybe I'll just jump right into JQuery. Quote Link to comment https://forums.phpfreaks.com/topic/264629-toggle-hidden/#findComment-1356400 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 23, 2012 Share Posted June 23, 2012 I have to agree that you must learn the fundamentals of JS before moving to jQuery. But jQuery helps shorten your script and there are many functions you could do with it. If I've solved your JS problems, please marked this topic as solved on the bottom of this page. Quote Link to comment https://forums.phpfreaks.com/topic/264629-toggle-hidden/#findComment-1356401 Share on other sites More sharing options...
BK201 Posted June 23, 2012 Author Share Posted June 23, 2012 The "Topic Solved" button has seemed to disappear. Quote Link to comment https://forums.phpfreaks.com/topic/264629-toggle-hidden/#findComment-1356402 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 23, 2012 Share Posted June 23, 2012 Ouh. I'll alert the devs. In the mean time, if you see any changes which are weird, please do reply to this topic. They recently had a new server. Quote Link to comment https://forums.phpfreaks.com/topic/264629-toggle-hidden/#findComment-1356407 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.