bondy666
asked on
How can I pass a classic asp vbscript variable from client side to server side?
I have a web page written in classic asp vbscript. What I need to do is return an integer from a msgbox so I can determine if the user has pressed OK or cancel. From what I understand, this is only possible using a client side script. This is fine, and I can determine whether OK or cancel is pressed as long as all subsequent code is client side. I can't seem to get anything to run server side. Any idea how I can do this? there must be a way somehow!
<%
If Request("TEST BUTTON") <> "" Then
%>
<script language="VBScript" type="text/vbscript">
int = msgbox("<%=Request("CollectionItems")%>",305)
msgbox "This works fine and = " & int
<%
Response.Write("MsgBox """ & "Server Side - this doesn't work and 'int' var isn't carried over = " & int & """</script>")
%>
End If
</script>
<%
End If
%>
here is a link on how to use forms with asp and the different ways of accessing the data.
http://www.w3schools.com/A SP/asp_inp utforms.as p
http://www.w3schools.com/A
Web applications are based on http protocol, which is based on a set of http request (from client to server) and a set of http responses (from server to client).
The unique way to pass information from client to server is by using an http request. There are two methods of doing this:
- GET method (usually calling a URL such as http://www.myserver.com/my_page.asp?parameter=value
- POST method (usually by using a HTTP FORM).
Both methods allow to send variables which server will receive as parameters. There are more advanced methods such as using AJAX, but behind there is the same technology.
Hope it helps.
The unique way to pass information from client to server is by using an http request. There are two methods of doing this:
- GET method (usually calling a URL such as http://www.myserver.com/my_page.asp?parameter=value
- POST method (usually by using a HTTP FORM).
Both methods allow to send variables which server will receive as parameters. There are more advanced methods such as using AJAX, but behind there is the same technology.
Hope it helps.
ASKER
OK, I understand that in the context of a submit button, but could you show me how this works with the code above? I'm probably being thick can't quite work out how I can get this to fire by pressing OK/cancel.
Thanks
Thanks
do you want to post back to the same page?
If so then do something like this
If so then do something like this
<script language="javascript">
window.location="file.asp?int=<?response.write(int)?>";
</script>
then where ever you want to deal with the response do something like thisif request.querystring("int")<>"" then
fill in what ever you need to do
end if
if you are not trying to work this on the same page, this work more or less the same way just more the second code block to the new page.
also don't forget to do
dim int
to create the variable before using it otherwise it isn't available and you should be throwing up errors about it
try something like this:
<%
If Request("TEST BUTTON") <> "" Then
%>
<script language="VBScript" type="text/vbscript">
int = msgbox("<%=Request("CollectionItems")%>",305)
msgbox "This works fine and = " & int
form.var.vale=int;
form.submit,
<%
Response.Write("MsgBox """ & "Server Side - this doesn't work and 'int' var isn't carried over = " & int & """</script>")
%>
End If
</script>
<form method="post">
<nput type="hidden" name="va">
/form>
<%
End If
%>
Toggle HighlightingOpen in New WindowSelect All
Tags:
Classic ASP, pass variable from client to server, vbscript Add Tags
Add Tags
ASKER
I have really tried with the examples above but have got nowehere so far.
haloexpertsexchange:
Assuming the second part is VBScript, I'm still not getting the variable passed over although it does look the neatest solution if I could get it to work.
gplana:
There seem to be a few typos (fair enough) but given my lack of asp experience it can be confusing. eg
form.var.vale=int;
Should this be form.var.value and should form be the actual name of the form in question (eg SCCMMain in my case? Also that line looks like javascript to me.
Also:
<nput type="hidden" name="va">
Obviously it's input, but what has the name="va" got to do with? not sure what this is about at all.
Thanks
haloexpertsexchange:
Assuming the second part is VBScript, I'm still not getting the variable passed over although it does look the neatest solution if I could get it to work.
gplana:
There seem to be a few typos (fair enough) but given my lack of asp experience it can be confusing. eg
form.var.vale=int;
Should this be form.var.value and should form be the actual name of the form in question (eg SCCMMain in my case? Also that line looks like javascript to me.
Also:
<nput type="hidden" name="va">
Obviously it's input, but what has the name="va" got to do with? not sure what this is about at all.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, getting closer but not quite there yet.
Instead of the variable being passed, the physical string is being passed. In the case above this equates to <?response.write(int)?> appearing.
This is progress as nothing was being passed before but unfortuanately <?response.write(int)?> isn't being ranslated into its correct value.
Instead of the variable being passed, the physical string is being passed. In the case above this equates to <?response.write(int)?> appearing.
This is progress as nothing was being passed before but unfortuanately <?response.write(int)?> isn't being ranslated into its correct value.
sorry sorry that was php syntax mostly there replace the <??> with <%%> and see what happens.
actually I was wondering if you wouldn't mind doing this entire thing in javascript instead of vbscript.
You can use a javascript confirm box which will give you instant reactions and then you can get the answer and do what ever you want no server side pass through necessary.
http://www.tizag.com/javas criptT/jav ascriptcon firm.php
You can use a javascript confirm box which will give you instant reactions and then you can get the answer and do what ever you want no server side pass through necessary.
http://www.tizag.com/javas
ASKER
Actually just sorted it. it was
window.location=file.asp?i nt=" + int;
Thank you so much for your time and effort. I consider myself a relatively confident vbscripter but classic asp seems to have so many little quirks that don't work in the way they should. Seems ironic that I would need some jscript to do what would normally be a simple function in vbscript. Anyway thank you again.
window.location=file.asp?i
Thank you so much for your time and effort. I consider myself a relatively confident vbscripter but classic asp seems to have so many little quirks that don't work in the way they should. Seems ironic that I would need some jscript to do what would normally be a simple function in vbscript. Anyway thank you again.
ASKER
Final script:
If Request("TEST BUTTON") <> "" Then
%>
<script language="VBScript" type="text/vbscript">
int = msgbox("<%=Request("CollMe nu")%>",30 5)
</script>
<script language="javascript">
window.location="SCCM_Main .asp?ans=" + int;
</script>
<%
End If
If Request.QueryString("ans") <>"" then
Response.Write("<" & "script language=VBScript>")
Response.Write("MsgBox """ & Request("int") & """</script>")
End If
I might look into the jscript alternative as well, look a bit neater!
If Request("TEST BUTTON") <> "" Then
%>
<script language="VBScript" type="text/vbscript">
int = msgbox("<%=Request("CollMe
</script>
<script language="javascript">
window.location="SCCM_Main
</script>
<%
End If
If Request.QueryString("ans")
Response.Write("<" & "script language=VBScript>")
Response.Write("MsgBox """ & Request("int") & """</script>")
End If
I might look into the jscript alternative as well, look a bit neater!
ASKER
Apologies, that should be
If Request("TEST BUTTON") <> "" Then
%>
<script language="VBScript" type="text/vbscript">
int = msgbox("<%=Request("CollMe nu")%>",30 5)
</script>
<script language="javascript">
window.location="SCCM_Main .asp?int=" + int;
</script>
<%
End If
If Request.QueryString("int") <>"" then
Response.Write("<" & "script language=VBScript>")
Response.Write("MsgBox """ & Request("int") & """</script>")
End If
If Request("TEST BUTTON") <> "" Then
%>
<script language="VBScript" type="text/vbscript">
int = msgbox("<%=Request("CollMe
</script>
<script language="javascript">
window.location="SCCM_Main
</script>
<%
End If
If Request.QueryString("int")
Response.Write("<" & "script language=VBScript>")
Response.Write("MsgBox """ & Request("int") & """</script>")
End If
The ok or cancel would be part of a form which submits to the asp page and from there you can take the request information and make different things happen based on what you were given as request data.