fortnox007 Posted October 1, 2010 Share Posted October 1, 2010 Hi all, I was playing around with javascript a bit and thought that i could maybe make a button when pressed hide a div and when pressed again shows it again. This is what i have so far, but it's not working, could anyone maybe point me in the right direction? <script type="javascript"> function hideDiv(){ document.getElementById('divver').style.display = none; } </script> <div id="divver"> <input type="checkbox" id="scb1" name="scb1" value="1" />As Seen On Tv<br /> <input type="checkbox" id="scb2" name="scb2" value="2" />Back To Basics<br /> <input type="checkbox" id="scb3" name="scb3" value="3" />Bed Bath & Beyond<br /> </div> <input type="button" onmouseover="hideDiv()" value="HIDE!!!"/> I haven't added the show div part because this first part isn't working yet. I bet making a button switch from hide to show is done with an if statement and a numeric value which is set. If anyone could see what i am doining wrong I would be very happy Quote Link to comment https://forums.phpfreaks.com/topic/214923-simple-hide-div-button/ Share on other sites More sharing options...
fortnox007 Posted October 1, 2010 Author Share Posted October 1, 2010 I changed the code a bit but still no succes. <script type="javascript"> function toggle(myobj) { var el = document.getElementById(myobj); if ( el.style.display != 'none' ) { el.style.display = 'none'; } else { el.style.display = ''; }} </script> <div id="mydiv"> <input type="checkbox" id="scb1" name="scb1" value="1" />As Seen On Tv<br /> <input type="checkbox" id="scb2" name="scb2" value="2" />Back To Basics <br /> <input type="checkbox" id="scb3" name="scb3" value="3" />Bed Bath & Beyond<br /> </div> <input type="button" onmouseover="toggle(mydiv);" value="HIDE!!!"/> Quote Link to comment https://forums.phpfreaks.com/topic/214923-simple-hide-div-button/#findComment-1118039 Share on other sites More sharing options...
fortnox007 Posted October 1, 2010 Author Share Posted October 1, 2010 OK i think i fixed it I had to put single quotes around the value in the button like: <input type="button" onmouseover="hideDiv('mydiv')" value="HIDE!!!"/> Could someone maybe explain me why that is, because within a function like below single quotes is not used? It's rather confusing for me at the moment. function hide_me(divver){ //etc } Quote Link to comment https://forums.phpfreaks.com/topic/214923-simple-hide-div-button/#findComment-1118101 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.