|
 |
asp_web_howto thread: Retrieve variable from Javascript window
Message #1 by "Ruth Bratton" <rubratton@d...> on Wed, 21 Feb 2001 20:40:04
|
|
I'm using a Javascript confirmation window to ask a question within a
section of VBScript in an ASP page. It works great, thanks to an example
I copied from this list. BUT, I don't know how to let ASP know what the
response was to the confirmation window. I'm putting the response in a
variable in the javascript portion:
response.write "window.status=(strPrereqsOK)?'confirm: true':'confirm:
false';" & vbCRLF
Then when I return to VBSCript and query strPrereqsOK, it's always false,
even though I click OK to the box.. I'm very new at this so I'm sure
there's a lot I don't understand! How can I pass the window response back
to my ASP page??
Message #2 by "Owen Mortensen" <ojm@a...> on Wed, 21 Feb 2001 14:39:51 -0700
|
|
strPrereqsOK is being set on the CLIENT side (i.e., in the browser). You
have to do something explicit (such as putting it in the query-string or in
a hidden form field) to get it back to the server.
Owen
-----Original Message-----
From: Ruth Bratton [mailto:rubratton@d...]
Sent: Wednesday, February 21, 2001 8:40 PM
To: ASP Web HowTo
Subject: [asp_web_howto] Retrieve variable from Javascript window
I'm using a Javascript confirmation window to ask a question within a
section of VBScript in an ASP page. It works great, thanks to an example
I copied from this list. BUT, I don't know how to let ASP know what the
response was to the confirmation window. I'm putting the response in a
variable in the javascript portion:
response.write "window.status=(strPrereqsOK)?'confirm: true':'confirm:
false';" & vbCRLF
Then when I return to VBSCript and query strPrereqsOK, it's always false,
even though I click OK to the box.. I'm very new at this so I'm sure
there's a lot I don't understand! How can I pass the window response back
to my ASP page??
Message #3 by "JstMeHr4u3" <jstmehr4u3@h...> on Wed, 21 Feb 2001 13:43:26 -0800
|
|
I don't know. But a hokey way of doing it is, put a hidden field on your
page, put the javascript VALUE into the field, and use that Field VALUE as
the value for your VbScript Variable. It kind of using your Javascript
variable to populate a field value, and your vbscript variable to get its
value from the field.
Words suck, maybe this will help.
JavaScript:
<input type= "hidden" value = (strPrereqsOK) name="Var1">
strPrereqs = "Hello"
Var1 = "Hello"
VbScript:
String1 = Var1
string1 = "Hello"
Mike
Message #4 by "Wally Burfine" <oopconsultant@h...> on Wed, 21 Feb 2001 22:32:02 -0000
|
|
I'm not sure what you are doing here, but I think you are using mixed
metafores. Server side Response.Write along with Client side confirm.
If you are doing it on the client side. Then everything should be in
JavaScript or VBScript. If you want to mix the script you can use a hidden
field that you populate with javaScript and read with VB Script.
Regards,
Wally
Message #5 by "Bratton, Ruth" <rubratton@d...> on Wed, 28 Feb 2001 11:09:09 -0500
|
|
I thank everyone for the suggestions. I'm trying to update a hidden field
with client side Javascript and then retrieve the value from that field with
VBScript. I feel like I"m getting close but I'm not there yet. My problem
may be in something really obvious, and I'm hoping someone might look at
this code and see immediately what's missing. Below is the code pulled out
of my ASP page.
Ruth
<%
... stuff deleted ...
If not isnull(strHasPrereqs) then
response.write ("<SCRIPT language=""JavaScript"">" & vbCRLF)
response.write ("var varPrereqsOK;") & vbCRLF
response.write ("varPrereqsOK = window.confirm('This course
has prerequisites. Will you have completed them?');" & vbCRLF)
response.write ("window.status=(varPrereqsOK)?'confirm:
true':'confirm: false';" & vbCRLF)
response.write
("document.EnterCourseRequests.vbPrereqsOK.value = ' + varPrereqsOK + '") &
vbCRLF
response.write ("</SCRIPT>" & vbCRLF)
strPrereqsOK = request.form("vbPrereqsOK")
end if
'* ... stuff deleted ....
>%
<form action="TreeVert.asp" Method=post Name="EnterCourseRequests">
<%
'* ... lots more stuff deleted ...
response.Write "<INPUT NAME='CRNSubmit'" & strWhichCRN & "
TYPE=Submit Value='Confirm CRN '" & strWhichCRN & " and press Enter'>"
'* the hidden field
response.Write "<INPUT NAME='vbPrereqsOK' TYPE=HIDDEN Value= " & "'"
& strPrereqsOK & "'" & ">"
%>
</form>
----------original question -------------------------
I'm using a Javascript confirmation window to ask a question within a
section of VBScript in an ASP page. It works great, thanks to an example
I copied from this list. BUT, I don't know how to let ASP know what the
response was to the confirmation window. I'm putting the response in a
variable in the javascript portion:
response.write "window.status=(strPrereqsOK)?'confirm: true':'confirm:
false';" & vbCRLF
Then when I return to VBSCript and query strPrereqsOK, it's always false,
even though I click OK to the box.. I'm very new at this so I'm sure
there's a lot I don't understand! How can I pass the window response back
to my ASP page??
Message #6 by "Wally Burfine" <oopconsultant@h...> on Wed, 28 Feb 2001 16:45:13 -0000
|
|
Do you get an error on this line on the server side?
response.write
("document.EnterCourseRequests.vbPrereqsOK.value = ' + varPrereqsOK + '") &
vbCRLF
It seems that it should be:
response.write
("document.EnterCourseRequests.vbPrereqsOK.value = varPrereqsOK" &
vbCRLF)
Regards,
Wally
>From: "Bratton, Ruth" <rubratton@d...>
>Reply-To: "ASP Web HowTo" <asp_web_howto@p...>
>To: "ASP Web HowTo" <asp_web_howto@p...>
>Subject: [asp_web_howto] Re: Retrieve variable from Javascript window
>Date: Wed, 28 Feb 2001 11:09:09 -0500
>
>I thank everyone for the suggestions. I'm trying to update a hidden field
>with client side Javascript and then retrieve the value from that field
>with
>VBScript. I feel like I"m getting close but I'm not there yet. My problem
>may be in something really obvious, and I'm hoping someone might look at
>this code and see immediately what's missing. Below is the code pulled out
>of my ASP page.
>
>Ruth
>
><%
>... stuff deleted ...
>
> If not isnull(strHasPrereqs) then
>
> response.write ("<SCRIPT language=""JavaScript"">" & vbCRLF)
> response.write ("var varPrereqsOK;") & vbCRLF
> response.write ("varPrereqsOK = window.confirm('This course
>has prerequisites. Will you have completed them?');" & vbCRLF)
> response.write ("window.status=(varPrereqsOK)?'confirm:
>true':'confirm: false';" & vbCRLF)
> response.write
>("document.EnterCourseRequests.vbPrereqsOK.value = ' + varPrereqsOK + '") &
>vbCRLF
> response.write ("</SCRIPT>" & vbCRLF)
> strPrereqsOK = request.form("vbPrereqsOK")
> end if
>
>'* ... stuff deleted ....
> >%
>
><form action="TreeVert.asp" Method=post Name="EnterCourseRequests">
><%
>'* ... lots more stuff deleted ...
>
> response.Write "<INPUT NAME='CRNSubmit'" & strWhichCRN & "
>TYPE=Submit Value='Confirm CRN '" & strWhichCRN & " and press Enter'>"
>
>'* the hidden field
> response.Write "<INPUT NAME='vbPrereqsOK' TYPE=HIDDEN Value= " & "'"
>& strPrereqsOK & "'" & ">"
>
>%>
></form>
>
>
>----------original question -------------------------
>
>I'm using a Javascript confirmation window to ask a question within a
>section of VBScript in an ASP page. It works great, thanks to an example
>I copied from this list. BUT, I don't know how to let ASP know what the
>response was to the confirmation window. I'm putting the response in a
>variable in the javascript portion:
>
>response.write "window.status=(strPrereqsOK)?'confirm: true':'confirm:
>false';" & vbCRLF
>
>Then when I return to VBSCript and query strPrereqsOK, it's always false,
>even though I click OK to the box.. I'm very new at this so I'm sure
>there's a lot I don't understand! How can I pass the window response back
>to my ASP page??
Message #7 by "Alex Shiell, ITS, EC, SE" <alex.shiell@s...> on Wed, 28 Feb 2001 17:10:24 -0000
|
|
document.EnterCourseRequests.vbPrereqsOK.value = ' + varPrereqsOK + '
should be
document.EnterCourseRequests.vbPrereqsOK.value = varPrereqsOK
otherwise your just assigning the string " + varPrereqsOK + " instead of the
value.
Little tip: Despite the discussions that have been going on recently about
doing a response.write() for each line being more efficient than closing the
asp tag (%>), writing some lines and re-opening the asp tag (<%), I would
certainly recommend that wherever you have a big block of HTML or
javascript, the latter option should be taken. The performance difference
would be so small that it would not be noticable, yet the code would be come
much easier to read and therefore far more maintainable.
If you had to fix a problem in an asp page someone else had written, what
would you rather see?
<%
If not isnull(strHasPrereqs) then
response.write ("<SCRIPT language=""JavaScript"">" & vbCRLF)
response.write ("var varPrereqsOK;") & vbCRLF
response.write ("varPrereqsOK = window.confirm('This course
has prerequisites. Will you have completed them?');" & vbCRLF)
response.write ("window.status=(varPrereqsOK)?'confirm:
true':'confirm: false';" & vbCRLF)
response.write
("document.EnterCourseRequests.vbPrereqsOK.value = ' + varPrereqsOK + '") &
vbCRLF
response.write ("</SCRIPT>" & vbCRLF)
strPrereqsOK = request.form("vbPrereqsOK")
end if
%>
or
<%
If not isnull(strHasPrereqs) then
%>
<SCRIPT language="JavaScript">
var varPrereqsOK;
varPrereqsOK = window.confirm('This course has prerequisites. Will
you have completed them?');
window.status=(varPrereqsOK)?'confirm:true':'confirm: false';
document.EnterCourseRequests.vbPrereqsOK.value = ' + varPrereqsOK +
'
</SCRIPT>
<%
strPrereqsOK = request.form("vbPrereqsOK")
end if
%>
In the second example the mistake is immediately obvious, whereas in the
first there's so many quotes all over the place that you might have to read
through the code many times before noticing the mistake.
Of course, response.write() should still be used when there is a big block
of ASP code which outputs text in various places.
-----Original Message-----
From: Bratton, Ruth [mailto:rubratton@d...]
Sent: Wednesday, February 28, 2001 4:09 PM
To: ASP Web HowTo
Subject: [asp_web_howto] Re: Retrieve variable from Javascript window
I thank everyone for the suggestions. I'm trying to update a hidden field
with client side Javascript and then retrieve the value from that field with
VBScript. I feel like I"m getting close but I'm not there yet. My problem
may be in something really obvious, and I'm hoping someone might look at
this code and see immediately what's missing. Below is the code pulled out
of my ASP page.
Ruth
<%
... stuff deleted ...
If not isnull(strHasPrereqs) then
response.write ("<SCRIPT language=""JavaScript"">" & vbCRLF)
response.write ("var varPrereqsOK;") & vbCRLF
response.write ("varPrereqsOK = window.confirm('This course
has prerequisites. Will you have completed them?');" & vbCRLF)
response.write ("window.status=(varPrereqsOK)?'confirm:
true':'confirm: false';" & vbCRLF)
response.write
("document.EnterCourseRequests.vbPrereqsOK.value = ' + varPrereqsOK + '") &
vbCRLF
response.write ("</SCRIPT>" & vbCRLF)
strPrereqsOK = request.form("vbPrereqsOK")
end if
'* ... stuff deleted ....
>%
<form action="TreeVert.asp" Method=post Name="EnterCourseRequests">
<%
'* ... lots more stuff deleted ...
response.Write "<INPUT NAME='CRNSubmit'" & strWhichCRN & "
TYPE=Submit Value='Confirm CRN '" & strWhichCRN & " and press Enter'>"
'* the hidden field
response.Write "<INPUT NAME='vbPrereqsOK' TYPE=HIDDEN Value= " & "'"
& strPrereqsOK & "'" & ">"
%>
</form>
----------original question -------------------------
I'm using a Javascript confirmation window to ask a question within a
section of VBScript in an ASP page. It works great, thanks to an example
I copied from this list. BUT, I don't know how to let ASP know what the
response was to the confirmation window. I'm putting the response in a
variable in the javascript portion:
response.write "window.status=(strPrereqsOK)?'confirm: true':'confirm:
false';" & vbCRLF
Then when I return to VBSCript and query strPrereqsOK, it's always false,
even though I click OK to the box.. I'm very new at this so I'm sure
there's a lot I don't understand! How can I pass the window response back
to my ASP page??
|
|
 |