Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 16th, 2003, 11:57 AM
Authorized User
 
Join Date: Jul 2003
Location: Urbana, IL, USA.
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>


Reply With Quote
  #2 (permalink)  
Old July 17th, 2003, 03:01 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:25 PM.


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