[Javascript] RE: Cookies & drop-down menus...

Kelly, Kyle Kyle at admin.usf.edu
Fri Aug 17 07:02:49 CDT 2001


one hint is that if it only set the cookie for the duration of the browser
session then the code that is being used to set the expiration date isn't
working. i wish i could give you the answer, but it's js and i'm pretty new
to it. 

-----Original Message-----
From: queequeg_x at yahoo.com [mailto:queequeg_x at yahoo.com]
Sent: Friday, August 17, 2001 7:54 AM
To: javascript at LaTech.edu
Subject: [Javascript] RE: Cookies & drop-down menus...


Cutter, thanks a ton for your help. One minor thing, tho'.

I put the code in as suggested. The drop down box worked but it 
didn't set the cookie. I tweaked it a little bit and it sort of 
worked. It set the cookie but only for the duration of the browser 
session. Could I trouble you to take a look at the code and tell me 
what I'm doing wrong? It would be greatly appreciated! Thanks a ton!!

-rene
--------------------------------------------
<html>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">
var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function setPage () {
	SetCookie ("region", document.forms[0].region.options
[document.forms[0].region.selectedIndex].value);
	document.location.href="http://webdev.pictel.com/intranet/test
/" + document.forms[0].region.options[document.forms
[0].region.selectedIndex].value;
}

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();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString
();
}

var favorite = GetCookie('region');
if (favorite != null) {
switch (favorite) {
case 'usa' : 	url = 'usa.asp';
	     	break;
case 'uk' : 	url = 'uk.asp'; 
	     	break;
case 'emeia' : url = 'emeia.asp';
		break;
case 'asia' : url = 'asia.asp';
		break;
}
window.location.href = favorite;
}
//  End -->
</script>
<title>Select your region</title>
<link rel="stylesheet" href="Assets/dialog.css" type="text/css">
</HEAD>
<BODY bgcolor="13548B">
<center>
<form>
    <p>Welcome to <br>
      <img src="Assets/mypictel.gif" width="163" height="42"></p>
    <table width="0">
      <tr>
        <td align="center"> 
          <p>Please select a region. </p>
          <hr>
          <!--<p> 
            <input type="radio" name="usa" onClick="SetCookie
('region', this.name, exp);">
            United States 
            <input type="radio" name="uk" onClick="SetCookie
('region', this.name, exp);">
            United Kingdom 
            <input type="radio" name="emeia" onClick="SetCookie
('region', this.name, exp);">
            EMEIA 
            <input type="radio" name="asia" onClick="SetCookie
('region', this.name, exp);">
            Asia-Pacific</p>-->
			<p><select name="region" onChange="setPage()">
              <option selected>--SELECT A REGION--</option>
              <option value="usa.asp">United States</option>
              <option value="uk.asp">United Kingdom</option>
              <option value="emeia.asp">EMEIA</option>
              <option value="asia.asp">Asia-Pacific</option>
            </select>
</p>
          <hr>
          <p>
            <input type="submit" name="Submit" value="Go to 
myPictureTel">
          </p>
          </td>
      </tr>
</table>
</form>
</center>
</body>
</html>

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
http://www.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list