Results 1 to 3 of 3

Thread: cookies

  1. #1

    Thread Starter
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    Unhappy

    Hi i wish to ask visitors to my page their age and stor it as a cookie for further viists my code goes like this


    if document.cookie = " "
    then vname =INPUTBOX("Please enter name")
    Document.Write "Hello" & " " & vname & " " & "and"
    cookie1= vname & ";expires=Wed, 07 Nov 2001 12:00:00 GMT"
    Document.Cookie = cookie1
    else
    cookie2= document.cookie
    document.write "Welcom back" & cookie2

    end if


    Can any one tell me what i am doing wrong, apart from pretending i am a programmer!!!!

    Thanks

  2. #2
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Looks to me like your trying to write a cookie from the client side code. Cookies are written to the client in the HTTP headers *before* a page is displayed. You have to submit your age value to a page (can even be the same page) that then writes the cookies BEFORE the HTML tag.

    Then the syntax is

    Code:
    'Write the cookie
    Response.Cookies("UserAge") = Request.Form("txtAge")
    Response.Cookies("UserAge").Expires = Date + 15
    and
    Code:
    'Read the cookie
    Dim intAge
    
    For each Item in Request.Cookies
    'You can also include any other cookies you have here to be read
        If Item="UserAge" Then
                intAge = CInt(Request.Cookies(Item))
        End If					
    Next
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  3. #3

    Thread Starter
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667
    HI I got my cookies to work, and by going along th road i started going down
    view code:


    dim cookier, cookiew, uname
    cookier=document.cookie
    mess= "Welcome back " & cookier
    if Len(mess)> 14 then
    else
    uname =INPUTBOX("Please enter name")
    mess = "hello"&" " & uname & " and"
    cookiew= uname & ";expires=Wed, 07 Nov 2001 12:00:00 GMT"
    Document.Cookie = cookiew
    End if
    document.write mess

    Try it out atsrburrows.20m.com

Posting Permissions

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



Click Here to Expand Forum to Full Width