KaineBennett Posted February 20, 2014 Share Posted February 20, 2014 Hello, I am using this on my menu-rightstats and its a dropdown but I want to keep it open all the time but I do not know how too.. This is the JS/PHP for it.. <div id="masterdiv"> <div id="ReloadThis"> <div onclick="change_m('stats')" class="heading">My Stats</div> <span id="stats" class="submenu"> This is the bit just above my stats.. and this is the javascript.. <script type="text/javascript"> var persistmenu="yes" var persisttype="sitewide" function change_m(obj){ if(document.getElementById){ var el = document.getElementById(obj); var ar = document.getElementById("masterdiv").getElementsByTagName("span"); if(el.style.display != "block"){ for (var i=0; i<ar.length; i++){ if (ar[i].className=="submenu") ar[i].style.display = "none"; } el.style.display = "block"; }else{ el.style.display = "none"; } } } function logo (){ var logout = confirm("Are you sure you want to logout?"); if (logout == true){ var loc = "../logout.php"; parent.location.href=loc; } } </script> Quote Link to comment Share on other sites More sharing options...
Dave Posted February 23, 2014 Share Posted February 23, 2014 Hello, I am using this on my menu-rightstats and its a dropdown but I want to keep it open all the time but I do not know how too.. This is the JS/PHP for it.. <div id="masterdiv"> <div id="ReloadThis"> <div onclick="change_m('stats')" class="heading">My Stats</div> <span id="stats" class="submenu"> This is the bit just above my stats.. and this is the javascript.. <script type="text/javascript"> var persistmenu="yes" var persisttype="sitewide" function change_m(obj){ if(document.getElementById){ var el = document.getElementById(obj); var ar = document.getElementById("masterdiv").getElementsByTagName("span"); if(el.style.display != "block"){ for (var i=0; i<ar.length; i++){ if (ar[i].className=="submenu") ar[i].style.display = "none"; } el.style.display = "block"; }else{ el.style.display = "none"; } } } function logo (){ var logout = confirm("Are you sure you want to logout?"); if (logout == true){ var loc = "../logout.php"; parent.location.href=loc; } } </script> Are you wanting to save the users choice so the next page they go to it has the same state? If so! You'll want to either save the users choice in their account so the system can read it on each request. This is probably the most ideal solution but it does mean creating an Ajax request to store that information. I'd read up here: http://www.w3schools.com/Ajax/ Using jQuery would be really benefical here as it provides an easy way to make the request and process the response. https://api.jquery.com/jQuery.ajax/ You could alternatively store the users choice within a cookie inside their browser which won't require any form of PHP backend. Manipulating cookies within the browser can be a bit confusing but here's a good introduction. http://www.w3schools.com/js/js_cookies.asp I'd really suggest using some form of library if you consider using cookies. https://github.com/ScottHamper/Cookies https://code.google.com/p/cookie-js/ Then you'd check server side (in the PHP) and set an inline style or add a class depending on the users choice. Also it maybe beneficial for you to use jQuery for the hide/showing of the block. It would also enable you to add in nice sliding/fading animations. http://jquery.com/ Quote Link to comment Share on other sites More sharing options...
KaineBennett Posted February 23, 2014 Author Share Posted February 23, 2014 I have got it how I want to get it but I want the dropdown to start off as being open if that makes any sense? Quote Link to comment Share on other sites More sharing options...
Script47 Posted February 23, 2014 Share Posted February 23, 2014 Dave's is probably best, but if you aren't going to keep the value for that long, why not look in to HTML5 & JS localstorage? 1 Quote Link to comment Share on other sites More sharing options...
jcvenom Posted February 23, 2014 Share Posted February 23, 2014 Are you wanting to save the users choice so the next page they go to it has the same state? If so! You'll want to either save the users choice in their account so the system can read it on each request. This is probably the most ideal solution but it does mean creating an Ajax request to store that information. I'd read up here: http://www.w3schools.com/Ajax/ Using jQuery would be really benefical here as it provides an easy way to make the request and process the response. https://api.jquery.com/jQuery.ajax/ You could alternatively store the users choice within a cookie inside their browser which won't require any form of PHP backend. Manipulating cookies within the browser can be a bit confusing but here's a good introduction. http://www.w3schools.com/js/js_cookies.asp I'd really suggest using some form of library if you consider using cookies. https://github.com/ScottHamper/Cookies https://code.google.com/p/cookie-js/ Then you'd check server side (in the PHP) and set an inline style or add a class depending on the users choice. Also it maybe beneficial for you to use jQuery for the hide/showing of the block. It would also enable you to add in nice sliding/fading animations. http://jquery.com/ I already mentioned to you about using jquery Quote Link to comment Share on other sites More sharing options...
Dave Posted February 23, 2014 Share Posted February 23, 2014 Dave's is probably best, but if you aren't going to keep the value for that long, why not look in to HTML5 & JS localstorage? HTML5 local storage is great and is supported by all modern browsers but till everyone wakes up and upgrades their browsers it's good practice to write a fallback. Which I imagine would be using cookies or storing it server side. +1 for promoting HTML5 I already mentioned to you about using jquery It's really beneficial if you're doing simple things like hide/show. http://blogs.learnnowonline.com/2012/10/03/7-benefits-of-jquery/ Quote Link to comment Share on other sites More sharing options...
Script47 Posted February 23, 2014 Share Posted February 23, 2014 HTML5 local storage is great and is supported by all modern browsers but till everyone wakes up and upgrades their browsers it's good practice to write a fallback. Which I imagine would be using cookies or storing it server side. +1 for promoting HTML5 It's really beneficial if you're doing simple things like hide/show. http://blogs.learnnowonline.com/2012/10/03/7-benefits-of-jquery/ Also I find it's a lot easier to use than cookies, it's lot less complicated which is a plus. Quote Link to comment Share on other sites More sharing options...
Dave Posted February 23, 2014 Share Posted February 23, 2014 Also I find it's a lot easier to use than cookies, it's lot less complicated which is a plus. I don't really understand who thought it'd be a great idea to make manipulating cookies such a difficult task. Quote Link to comment Share on other sites More sharing options...
Script47 Posted February 24, 2014 Share Posted February 24, 2014 I don't really understand who thought it'd be a great idea to make manipulating cookies such a difficult task. Exactly, if they based it of the local storage code then I would surely use cookies, but oh well. 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.