[Javascript] Cookies & drop down menus

queequeg_x at yahoo.com queequeg_x at yahoo.com
Thu Aug 16 10:03:43 CDT 2001


I have this code that's meant to select a region's site and go to it. 
The next time you enter, it brings you directly there.

Now, I've gotten this to work with radio buttons and check boxes. My 
silly question is: how do I get it to work with a drop-down box. Many 
thanks in advance.

-rene

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

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

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 = url;
}
//  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>
          <hr>
          <p>
            <input type="submit" name="Submit" value="Go to 
myPictureTel">
          </p>
          </td>
      </tr>
</table>
</form>
</center>
</body>
</html>




More information about the Javascript mailing list