Hi frendz,
Can we set a value for a session variable through javascript onclick event?
(or)
How can we set a global variable for the whole website using javascript?

I'm using AJAX to set session and my problem is solved.

<script type="text/javascript">
	function setLeft(str)
	{
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				if(str=="hide")
				{
					document.getElementById("left_side").style.display='none';
					document.getElementById("left_side_show").style.display='';
				}
				if(str=="show")
				{
					document.getElementById("left_side").style.display='';
					document.getElementById("left_side_show").style.display='none';
				}
			}
		}
		xmlhttp.open("GET","setSession.php?q="+str,true);
		xmlhttp.send();
	}
</script>

setSession.php

<?php
	@session_start();
	$_SESSION["ses_left"]=$_GET["q"];
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.