herghost Posted September 26, 2010 Share Posted September 26, 2010 Hello everyone, this is one of my 1st attempts of using js, and its confusing me This is my code: <html> <head> <title></title> <script type="text/javascript"> var cats = ["electronics", "entertainment", "homeandgarden", "finance", "motoring", "fashion", "travel", "medical",]; var electronics = ["mobiles", "hi-fi"]; var entertainment = ["books", "dvds",]; function check() { document.getElementById("checkbox").checked = "checked"; } function visiblox(arrDiv, hs) { var disp = (hs) ? "none" : "block"; for(var x = 0; x < arrDiv.length; x++) { document.getElementById(arrDiv[x]).style.display = disp; } } function chk(what, item) { if(item) { visiblox(what, false); } else { visiblox(what, true); } } </script> <style type="text/css"> <!-- .hide { display: block; } .hide { display: none; } --> </style> </head> <body> <img src="images/electronics.png" onclick="javascript:check();"> <input type="checkbox" id="checkbox" onclick="chk(electronics, this.checked);"> <br> <input type="checkbox" onclick="chk(entertainment, this.checked);" checked> Entertainment<br> <br> <br> <div id="mobiles" class="hide">Mobiles</div><br> <div id="hi-fi" class="hide">Hi-Fi</div><br> <div id="books" class="hide">Books</div><br> <div id="dvds" class="hide">DVD's</div><br> </body> </html> Basically I am having some problems with the electronics input, it just doesnt display the divs when clicked, why is this? Quote Link to comment https://forums.phpfreaks.com/topic/214477-checkbox-help-showhide-divs-using-images/ Share on other sites More sharing options...
brianlange Posted September 27, 2010 Share Posted September 27, 2010 It works fine for me. I put the code up on my website http://www.realtown.com/js-test.php Are you getting an error? By the way have a array with all of the values is not really necessary. You could wrap the divs within another div with the name "electronics" and just process all of the child elements of the div. -Brian Quote Link to comment https://forums.phpfreaks.com/topic/214477-checkbox-help-showhide-divs-using-images/#findComment-1116404 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.