Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2003, 11:57 AM
Authorized User
 
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default getting set cookie value from a script

I have a dropdown menu that is populated by an external file.

I want to place what the user selects in my cookie.
My cookie works great for the user_name and user_phone...but I can't get it to work with my ad_code...the cookie does not save that information...when I call for the info from the cookie this part is blank. What have I done wrong?

<head>
<script language="JavaScript">
function setCookie() {
  var expiresDate = new Date();
  expiresDate.setFullYear(expiresDate.getFullYear() + 1);
  document.cookie = encodeURI("user_name="
    + document.twork.proc_by.value) + "; expires="
    + expiresDate.toUTCString();
  document.cookie = encodeURI("user_phone="
    + document.twork.procphone.value) + "; expires="
    + expiresDate.toUTCString();
  document.cookie = encodeURI("ad"
    + document.twork.ad_code.options[document.twork.ad_code.selectedIndex].value) + "; expires="
    + expiresDate.toUTCString();
}
</script>
</head>

<body>
<script language="JavaScript">
     document.write("<select name=\"ad_code\" id=\"ad_code\" size=\"1\" class=\"regSoft\" onBlur=\"doSetAd()\">");
     for(i=0; i<divCodes.length; i++){
      document.write("<option>");
      document.write(divCodes[i]);
      document.write("</option>");
     }
     document.write("</select>");
</body>


 
Old July 17th, 2003, 03:01 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Your select box doesn't have values in the option tags, only text so change this line:
Code:
document.twork.ad_code.options[document.twork.ad_code.selectedIndex].value
to
Code:
document.twork.ad_code.options[document.twork.ad_code.selectedIndex].text
OR
change:
Code:
document.write("<option>");
document.write(divCodes[i]);
document.write("</option>");
to
Code:
document.write("<option value=\"" + divCodes[i] + "\">");
document.write(divCodes[i]);
document.write("</option>");

--

Joe





Similar Threads
Thread Thread Starter Forum Replies Last Post
Set-Cookie: PHPSESSID=deleted ajit Beginning PHP 0 October 23rd, 2007 08:29 AM
set the cookie file name crmpicco Javascript How-To 4 February 17th, 2006 05:04 AM
Set Cookie Chapter 8 ? phirun BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 13 May 27th, 2005 11:19 AM
Use cookie to set main frame npepin Javascript 0 October 18th, 2004 02:01 PM
Set Cookie rowlandk Beginning PHP 5 April 6th, 2004 01:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.