Results 1 to 2 of 2

Thread: Cookies - Need some help

  1. #1
    Senior Member
    Join Date
    Jan 2008
    Posts
    204
    Thanks
    5
    Thanked
    5 times in 5 posts

    Cookies - Need some help

    Hello,

    I'm trying to validate a form selling "Widgets" using JavaScript. So far I have the validation bit done and I'm really happy with what I've done so far! I now have to move on to the cookies part. Basically, I want there to be a confirmation page which shows all of the details entered in the form and calculates the total price. I need a little help with setting the cookies.

    I start off by using this code:

    Code:
     function setCookie(name, value)
          {
            document.cookie = name + "=" + escape(value)
            
          }
    Now I need to set the data entered into the form as cookies. How would I do that? I don't want someone to do it for me, I just want to know how I would use setCookie("name","value") to work with my form.

    Thanks in advance,
    Steven

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Cookies - Need some help

    This would be better achieved server-side tbqh...

    Code:
    // Unverified, untested
    onclick = function () { 
      var MyForm = document.getElementById('myform');
      for (i=0; i<MyForm.elements.length; i++) {
        setCookie(MyForm[i].id, MyForm[i].value);
      }
    }
    Of course, your cookie function may produce unexpected results (overwriting for e.g.).
    To err is human. To really foul things up ... you need a computer.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. bacon cookies!
    By directhex in forum Kitchen and Cooking
    Replies: 18
    Last Post: 07-02-2008, 05:11 PM
  2. Roaming Profile Cookies
    By Olly1234 in forum Software
    Replies: 3
    Last Post: 10-12-2005, 11:29 PM
  3. Firefox Cookies
    By Matt1eD in forum Networking and Broadband
    Replies: 2
    Last Post: 26-03-2005, 01:16 PM
  4. Virtual Cookies
    By dkmech in forum HEXUS Suggestions
    Replies: 0
    Last Post: 15-07-2004, 09:02 AM
  5. best place for cookies and cookiejars?
    By prehensile in forum Retail Therapy and Bargains
    Replies: 13
    Last Post: 19-11-2003, 08:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •