I have been using cookies for quite some time now, but am not sure what they are - browser cookies or session cookies
See if my sample code is indeed using session cookies using JavaScript, and if we are on the same page, then we can move ahead with some discussion later.
Code from sridhar_rao_1.htm:
Code:
<HTML>
<HEAD>
<TITLE>Sridhar Rao</TITLE>
<script language='JavaScript'>
function doCooking()
{
//document.SridharsForm.SubmitButton.disabled='true';
if(cookieExists())
{
alert('Stop fooling around, nigga!');
return false;
}
else
{
setCookie(5); // 5 minutes
alert('Good going, mate!');
}
return true;
}
function cookieExists()
{
if(document.cookie.length > 0)
{
var begin = document.cookie.indexOf("SriCookie=");
if(begin != -1)
{
begin += "SriCookie".length + 1;
var end = document.cookie.indexOf(";", begin);
if(end == -1)
end = document.cookie.length;
if('true' == unescape(document.cookie.substring(begin, end)))
return true;
}
}
return false;
}
function setCookie(expiryMins)
{
var ExpireDate = new Date();
ExpireDate.setTime(ExpireDate.getTime() + (expiryMins * 60 * 1000));
document.cookie = "SriCookie=true" + ((expiryMins == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
function deleteCookie()
{
if(cookieExists())
document.cookie = "SriCookie=; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
</script>
</HEAD>
<BODY>
<form name='SridharsForm'>
Poll. Question#1
<LI>Blah Blah Blah... Choice 1</LI>
<LI>Blah Blah Blah... Choice 2</LI>
<LI>Blah Blah Blah... Choice 3</LI><BR><BR>
<input type='radio' name='SridharRao1' value='1'/>1<BR>
<input type='radio' name='SridharRao1' value='2'/>2<BR>
<input type='radio' name='SridharRao1' value='3'/>3<BR>
<input type='submit' name='SubmitButton' value='Submit' onClick='return doCooking()'/>
<input type='button' name='NextPage' value='Next Page ==>' onClick='window.location="sridhar_rao_2.htm"'/>
<BR><BR><BR><BR><BR><BR><BR><BR>
<input type='button' name='ClearButton' value='Clear Cookie (just to test)' onClick='deleteCookie()'/>
</form>
</BODY>
</HTML>
Code from sridhar_rao_2.htm:
Code:
<HTML>
<HEAD>
<TITLE>Sridhar Rao</TITLE>
<script language='JavaScript'>
function doNothing()
{
return false;
}
</script>
</HEAD>
<BODY>
<form name='SridharsForm'>
Poll. Question#2
<LI>Dooo da doo da do... Choice 1</LI>
<LI>Dooo da doo da do... Choice 2</LI>
<LI>Dooo da doo da do... Choice 3</LI><BR><BR>
<input type='radio' name='SridharRao2' value='1'/>1<BR>
<input type='radio' name='SridharRao2' value='2'/>2<BR>
<input type='radio' name='SridharRao2' value='3'/>3<BR>
<input type='button' name='PrevButton' value='<== Previous page' onClick='window.location="sridhar_rao_1.htm"'/>
<input type='submit' name='SubmitButton' value='Submit' onClick='return doNothing()'/>
</form>
</BODY>
</HTML>
Copy the above 2 code snippets as sridhar_rao_1.htm and sridhar_rao_2.htm respectively.
Tip: If you uncomment the line document.SridharsForm.SubmitButton.disabled='true'
you might have almost similar result as you expect without using cookies, leaving apart the page refresh option though.