Help, trying to process html select variable to session variable via jquery and php

Currently when I change the select option it correct dials up the js code at the top of the form, but then I’m not sure if it’s actually calling the php script, falling over somewhere in the process, the zombie apocalypse has started as I’m not getting anything back … I think … dazed and confused folks.

What I want to do is change the Session variable theme on change of the html select :frowning:


<?php
	session_start();
	if(!isset($_SESSION['theme'])) {
		$style_dir = "./standard";
	} else {
		$style_dir = $_SESSION['theme'];
		die("theme ".$style_dir);
	}
	
?>

<!DOCTYPE html>
<html>
	<head>
		<title>Test page</title>
		<script src="./js/jquery.js"></script>
		<script>
			function themeChange(){
				var myselect = document.getElementById("theme");
				var theme = myselect.options[myselect.selectedIndex].value;
				var datastr = "style=" + theme;
				alert(theme);
				//Call php to change the server side session variable
				$.ajax({
					type: "POST",
					url: "theme.php",
					data:datastr,
					success:function(){
						var variable = '<%= Session["theme"] %>';
						alert("Style : " + variable);
						location.reload();
					}
				})
			}
		</script>
	</head>
	<body>
		<h1>Current Theme&nbsp;|&nbsp;<?php echo($style_dir); ?></h1>
		<h3>Select theme</h3>&nbsp;&nbsp;
		<select id="theme" onchange="themeChange()">
			<option value="standard">Standard</option>
			<option value="orange">Orange</option>
			<option value="purple">Purple</option>
		</select>
	</body>
</html>

and the simply php stuff


<?php
session_start()

	$theme = $_POST["style"];
	$_SESSION['theme'] = "./".$theme;
	
?>

Echo out the style when you update the session, and then the success method will be able to receive that echo as a response, for your confirmation.



```javascript

$_SESSION['theme'] = "./".$theme;
echo $theme;


success: function (response) {
    alert("Style : " + response);
    location.reload();
}