Jump to content
MakeWebGames

Div Onclick help.....!


KaineBennett

Recommended Posts

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>
Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...