Hi,
I'm having a hard time with the following.
I have a PHP page with a form containing a check box. I need to set a cookie with the value of the checkbox ie either enabled or disabled such that when the page is regenerated based on the check field criteria the checkbox is enabled if it were before or else if a person had enabled the feature the last time the page was visited the checkbox is enabled.
I've modified a snippet of code that I found online to set the value of the checkbox but it doesn't seem to work.Could someone see what is wrong.
Thanks
<?php
SetCookie("optioncookie",$optionenabled);
if(isset($optioncookie))
{
echo "Cookie just set.<BR>";
}
else
{
echo "Cookie was not set.<BR>";
}
?>
<HEAD>
<script language="JavaScript">
// Original JavaScript code by Duncan Crombie: dcrombie at chirp.com.au
// Please acknowledge use of this code by including this header.
function getCookie(name) { // use: getCookie("name");
var bikky = document.cookie;
var index = bikky.indexOf(name + "=");
if (index == -1)
{
//if cookie not set
document.form.optionenabled.value =$optionenabled;
return null;
}
index = bikky.indexOf("=", index) + 1; // first character
var endstr = bikky.indexOf(";", index);
if (endstr == -1) endstr = bikky.length; // last character
document.form.optionenabled.value = unescape(bikky.substring(index, endstr));
}
</script>
</HEAD>
<BODY onload="getCookie('optioncookie')">
<?php
echo "<form action= \"cookie.php4\" name=\"form\" method =\"post\">";
?>
Provider :<input type="checkbox" name="optionenabled" >
<input type=image src="button.gif" BORDER = 0 onClick="submit" >
</form>
</BODY>