-
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
-
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
-
HI I got my cookies to work, and by going along th road i started going down :D
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