[Javascript] Cookies & drop down menus

Cutter Bl cutterbl at hotmail.com
Thu Aug 16 11:01:19 CDT 2001


you could create a function

function setPage(){
     document.location.href="http://www.mysite.com/' + 
myForm.SelectBox.options[myForm.SelectBox.selectedIndex].value + '";
}

And you use the page name as the value of the options in your select. You 
then reference the function in the selects onclick event...

onclick="setPage()"

Just a thought. Hope it helps.

Cutter
http://www.falcon-knives.com
**************************************
From: queequeg_x at yahoo.com
Reply-To: javascript at LaTech.edu
To: Javascript at LaTech.edu
Subject: [Javascript] Cookies & drop down menus
Date: Thu, 16 Aug 2001 15:03:43 -0000

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>

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


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




More information about the Javascript mailing list