#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Edinburgh, UK
    Posts
    1
    Rep Power
    0

    Javascript - read cookie & incorperate results into form


    I'm kind of a newbie so if this is an easy one i apologise...

    I have some js script on a couple of my pages that I want to develop further. It sets a cookie which is a little list of free samples that browsers can create as they browse the site...

    Based on the to-do-list found here...
    http://javascript.internet.com/cookies/to-do-list.html

    What I want this to do is work a bit like a shopping cart except that all the perl carts I looked at were over complicated in that they all ask for payment...

    Below is the function for displaying the list within the html on a page


    function ListToDoItems() {
    var NumToDoItems = GetCookie('PT_NumToDoList');
    var i;
    var ToDoItem;
    if (NumToDoItems == null) {
    NumToDoItems = 0;
    }
    ShowCount = 0; SwapColour = 0;
    for (i=1; i <= NumToDoItems; i++) {
    ToDoItem = GetCookie('PT_ToDoItem'+i);
    if (ToDoItem != null) {
    PrintItem(ToDoItem, i);
    }


    calling the ListToDoItems(); function on the page then display's the list...

    i.e.
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    ListToDoItems();
    // End -->
    </SCRIPT>

    What I am now wanting to do is incorperate this information into a form so that it can be sent (post) using formmail
    i.e. I want the ListToDoItems(); function to be sent using formmail
    I have tried
    <input type="hidden" name="fieldname" value="ListToDoItems();">
    which doesn't work..

    Like I said I'm learning & don't know a lot about javascript yet!!
    Last edited by 5sisters; April 26th, 2003 at 03:34 AM.
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Try this
    Code:
    function ReturnToDoItems() {
      var out = '';
      var NumToDoItems = GetCookie('PT_NumToDoList');
      var i;
      var ToDoItem;
      if (NumToDoItems == null) {
        NumToDoItems = 0;
      }
      ShowCount = 0; SwapColour = 0;
      for (i=1; i <= NumToDoItems; i++) {
        ToDoItem = GetCookie('PT_ToDoItem'+i);
        if (ToDoItem != null) {
          out += ToDoItem;
        }
      }
      return out;
    }
    -james

IMN logo majestic logo threadwatch logo seochat tools logo