[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1594
  • Last Modified:

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

%>

Open in new window

0
bondy666
Asked:
bondy666
  • 7
  • 6
  • 2
1 Solution
 
haloexpertsexchangeCommented:
You pass information from the client side to the server side by submitting information in a form of some kind.
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.
0
 
haloexpertsexchangeCommented:
here is a link on how to use forms with asp and the different ways of accessing the data.

http://www.w3schools.com/ASP/asp_inputforms.asp
0
 
gplanaCommented:
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bondy666Author Commented:
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
0
 
haloexpertsexchangeCommented:
do you want to post back to the same page?
If so then do something like this
<script language="javascript">
window.location="file.asp?int=<?response.write(int)?>";
</script>

Open in new window

then where ever you want to deal with the response do something like this
if request.querystring("int")<>"" then
fill in what ever you need to do

end if

Open in new window

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.
0
 
haloexpertsexchangeCommented:
also don't forget to do
dim int 

Open in new window

to create the variable before using it otherwise it isn't available and you should be throwing up errors about it
0
 
gplanaCommented:
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

Open in new window

0
 
bondy666Author Commented:
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
0
 
haloexpertsexchangeCommented:
have you gotten any errors?
If so please let us know.
Also where did you place the javascript that I gave you?
It is meant to be placed right after where you give int a value.
Also the second part of it I would suggest putting as part of an if statement that goes something like this
<%if request.querystring("int")<>"" then
fill in what ever you need to do
else %>
<script language="VBScript" type="text/vbscript">

int = msgbox("<%=Request("CollectionItems")%>",305)

msgbox "This works fine and = " & int

</script>
<script language="javascript">
window.location="file.asp?int=<?response.write(int)?>";
</script>

<%end if%>

Open in new window

See if something like this helps you put it all together.
As for what script I wrote the if statement, it is in classic asp vb.
0
 
bondy666Author Commented:
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.
0
 
haloexpertsexchangeCommented:
sorry sorry that was php syntax mostly there replace the <??> with <%%> and see what happens.
0
 
haloexpertsexchangeCommented:
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/javascriptT/javascriptconfirm.php
0
 
bondy666Author Commented:
Actually just sorted it. it was

window.location=file.asp?int=" + 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.
0
 
bondy666Author Commented:
Final script:
If Request("TEST BUTTON") <> "" Then

%>
<script language="VBScript" type="text/vbscript">
int = msgbox("<%=Request("CollMenu")%>",305)
</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!
0
 
bondy666Author Commented:
Apologies, that should be

If Request("TEST BUTTON") <> "" Then

%>
<script language="VBScript" type="text/vbscript">
int = msgbox("<%=Request("CollMenu")%>",305)
</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
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 7
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now