Discussion:
Newbie: 3 Lines - Why doesn't it work.
(too old to reply)
unknown
2006-08-23 04:17:04 UTC
Permalink
Any help appreciated

Trying to pass javascript prompt value to asp for processing.

Each time I refresh the page, the asp code writes the previous
prompt's value. Is the cookie not written before the asp code
executes?

Many thanks in advance.


<script type="text/javascript">
var a = prompt("Enter Password please!");
document.cookie = "test=" + escape(a) + "; expires=1/1/2010";
</script>

<%
response.write "test=" & Request.cookies("test") & "<br>"
%>
Evertjan.
2006-08-23 07:11:31 UTC
Permalink
Post by unknown
Trying to pass javascript prompt value to asp for processing.
In fact, you try but do not send to ASP,
you pass it to a [clientside!!] cookie,
and that cookie is only send to the server on the next page request.
Post by unknown
Each time I refresh the page, the asp code writes the previous
prompt's value. Is the cookie not written before the asp code
executes?
No, ASP code is executed serverside [=on the server], and does not know
and does not want to know what is happening clientside [= in the
browser].
Post by unknown
<script type="text/javascript">
var a = prompt("Enter Password please!");
document.cookie = "test=" + escape(a) + "; expires=1/1/2010";
</script>
<%
response.write "test=" & Request.cookies("test") & "<br>"
%>
This works, as expected, fine, on refrech, as you said.

================================

Only the expires date is not according to specs, try:

<script type="text/javascript">
var a = prompt("Enter Password please!");
document.cookie = "test=" +
escape(a) +
"; expires=Thu, 25 Aug 2006 23:12:48 UTC; path=/"
</script>

<%
response.write "test=" & Request.cookies("test") & "<br>"
%>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
unknown
2006-08-23 09:17:00 UTC
Permalink
On 23 Aug 2006 07:11:31 GMT, "Evertjan."
Post by Evertjan.
This works, as expected, fine, on refrech, as you said.
Hi Evertjan

Thanks man, now I see. The asp code has already executed server-side
before the javascript even hits the browser.

I'm an idiot, don't ask me why us newbies know and understand that
principle, and still don't grasp its significance until some code
fails, and its restated by someone.

Thanks again man

Kenny

Loading...