Can someone help me modify this "password example" so that it works. Currently it just calls "alert()" statements when it is suppose to save, get, and delete a cookie. I need to replace those "alert()" calls with the appropriate cookie call (GetCookie,
SetCookie, DeleteCookie
This program stores a password in the user's browser's cookie file, and then checks that file in the future to confirm the password. Display a 'password correct' or a 'password failed' message. I also want to have a button that deletes the cookie!!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<script language="JavaScript">
<!-- hide from non-JavaScript browsers
//expires in 24 hours - please use this!
// end hide -->
</script>
</HEAD>
<BODY>
Note: This example does not work. I need some help to make it work! <br>
All the pieces are here and in the "cookie" example. <br>
Display a 'password correct' or a 'password failed' message. <br>
I need to use the expiration date declared in the code for my cookie. <br>
I need to replace the "alert" functions with calls to cookie functions. <br>
<hr>
<br>
<form name='pwCheck'>
Enter a password to be stored in a cookie:
<input type='password' name='pwEnter' size=8><br>
<input type='button' value='Submit Password to Cookie' onClick="alert(document.pwCheck.pwEnter.value)"><br>
<hr>
Enter a password to be checked:
<input type='password' name='pwConfirm' size=8><br>
<input type='button' onClick="alert(document.pwCheck.pwConfirm.value)" value='Confirm Password from Cookie'><br>
<hr>
<input type='button' onClick="alert('Please delete the cookie!!')" value='Delete Password Cookie'><br>
</form>
</BODY>
</HTML>
SetCookie, DeleteCookie
This program stores a password in the user's browser's cookie file, and then checks that file in the future to confirm the password. Display a 'password correct' or a 'password failed' message. I also want to have a button that deletes the cookie!!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<script language="JavaScript">
<!-- hide from non-JavaScript browsers
Code:
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie(name) {
var exp = new Date();
FixCookieDate (exp); // Correct for Mac bug
exp.setTime (exp.getTime() - 1); // This cookie is history
var cval = GetCookie (name);
if (cval != null)
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var expdate = new Date();
expdate.setTime(expdate.getTime()+(24*60*60*1000));
// end hide -->
</script>
</HEAD>
<BODY>
Note: This example does not work. I need some help to make it work! <br>
All the pieces are here and in the "cookie" example. <br>
Display a 'password correct' or a 'password failed' message. <br>
I need to use the expiration date declared in the code for my cookie. <br>
I need to replace the "alert" functions with calls to cookie functions. <br>
<hr>
<br>
<form name='pwCheck'>
Enter a password to be stored in a cookie:
<input type='password' name='pwEnter' size=8><br>
<input type='button' value='Submit Password to Cookie' onClick="alert(document.pwCheck.pwEnter.value)"><br>
<hr>
Enter a password to be checked:
<input type='password' name='pwConfirm' size=8><br>
<input type='button' onClick="alert(document.pwCheck.pwConfirm.value)" value='Confirm Password from Cookie'><br>
<hr>
<input type='button' onClick="alert('Please delete the cookie!!')" value='Delete Password Cookie'><br>
</form>
</BODY>
</HTML>