Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Cookies 1

Status
Not open for further replies.

JackD4ME

Programmer
Jun 4, 2002
228
US
HI Everyone,
I am trying to create a cookie with vbscript. No matter what syntax I use it errors out on the line with the response object. I am new to asp and vbscript and the books aren't working.

Sub Login_onclick
window.alert (uspw.user.value)
Response.Cookies("OilLogin")("User")=(uspw.User.value) 'uspw is the name of the form
window.alert (request.cookies("OilLogin")("User"))
End Sub

The first msgbox appears with the correct input data but then nothing! I know this is simple and should work but does not. Can someone please help?
 
dunno if this helps you

<% tempstr=&quot;Hello&quot; %>
<script language=jscript>
window.alert (&quot;<%=tempstr%>&quot;)
<%
Response.Cookies(&quot;OilLogin&quot;)(&quot;User&quot;)=tempstr
response.cookies(&quot;OilLogin&quot;).expires=date+1

tempcookie=request.cookies(&quot;oilLogin&quot;)(&quot;user&quot;)
%>
window.alert (&quot;<%=tempcookie%>&quot;)
</script>
 
I have set the user variable to a string and then used a msgbox to see if it worked, it did. But I still get a &quot;Object Required: 'Response'&quot; error. Why is the browser looking for n object when all it is doing is creating a cookie (which it is not even doing that!)?
 
You can't include the response.cookies in a vbscript sub. response is an asp object. This is why in your code above vbscript is looking for an object called response and it doesn't know what it is. Here is a simple example that might be able to point you in the right direction:

<%@ language=&quot;VBSCRIPT&quot;%>
<%Response.Cookies(&quot;USER&quot;) = &quot;USERID&quot;
Response.Cookies(&quot;USER&quot;).expires = (now() + 1)%>
<html>
<head>
<title>test</title>
<script language=vbscript>
sub test(user)
window.alert(user)
end sub
</script>
</head>
<BODY>
<%Response.write &quot;Display USER on page: &quot; & Request.Cookies(&quot;USER&quot;)%>

<form name=form1>
<input type=text value=&quot;<%=Request.Cookies(&quot;USER&quot;)%>&quot; name=text1><BR>
<input type=button value=&quot;Push me&quot; name=button1 onclick='test(&quot;<%=Request.Cookies(&quot;USER&quot;)%>&quot;)'>
</form>
</body>
</html>

Hope that helps...
mwa

 
I have added a number of lines to this code. The closest I got to getting anything was &quot;OilLogin&quot; in the msgbox. I added the code above the <HTML> and the onclick into the button. Now I keep getting an error of &quot;expected ')'&quot; in the line with the onclick. Here is the code I currently have:

<%@ language=&quot;VBSCRIPT&quot;%>
<%Response.Cookies(&quot;OilLogin&quot;)(&quot;USER&quot;) = &quot;USERID&quot;
Response.Cookies(&quot;OilLogin&quot;)(&quot;USER&quot;).expires = (now() + 1)%>
<html>
<script language=vbscript>
Sub Login((OilLogin)(User))
window.alert ((OilLogin)(User))
end sub
</script>

....

<form name=uspw>
<input Type=text name=&quot;User&quot;>
<input Type=password name=&quot;PW&quot;>

<input Type=BUTTON NAME=&quot;LoggedIn&quot; VALUE=&quot;Login&quot; onclick='Login(&quot;<%=Request.Cookies(&quot;OilLogin&quot;)(&quot;USER&quot;)%>&quot;)'>
</form>

I cannot see where I am missing a (. Please help.
Is dealing with cookies always this much of a hassle? Frustration is boiling over! Thanks for all the help.

Jack D
 
Response.Cookies(&quot;OilLogin&quot;).expires = (now() + 1)%>
 
Also, when you call the sub, you are only passing one varibale:

onclick='Login(&quot;<%=Request.Cookies(&quot;OilLogin&quot;)(&quot;USER&quot;)%>&quot;)'>

therefore you only need to have one variable between the parenthesis of the sub:

Sub Login(User)
window.alert (User)
end sub
 
You cannot set AND read a cookie on the same page without a reload/refresh (unlike JavaScript, which can read them immediately).

Try setting the cookie on one page, and then create a second page to &quot;read&quot; it back out - as long as cookies are enabled, it should work fine.

Here's an article dealing with setting and reading cookies; although it talks specifically about &quot;checking to see if cookies are enabled or not, it deals with thie issue of not being able to set and read a cookie on the same page.
Hope this helps.
Ciao, K----------------
&quot;If you were supposed to understand it, we wouldn't call it code&quot; - FedEx
 
Thank you all so much. My problem was trying to set a cookie and read it on the same page. You guys rock!

Jack
 
Shouldn't you be in the cooking forum if you want to bake cookies?

B


&quot;There's nothing like a nice piece of pie.&quot; - Bill Cosby
 
Kim, wonderful information, thanks for another great link to add to my library.
-Tarwn The three most dangerous things in the world are a programmer with a soldering iron, a hardware type with a program patch, and a user with an idea
-computer saying (Wiz Biz - Rick Cook)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top