views:

76

answers:

3

I'm new to VBscript so there is probably a very simple solution to this.

Basically, I have my main page with buttons that really just act as links to other pages. In the links I wanted to pass information, so I use the standard ?variable=value like so:

<input type="button" name="saveButton" value="Save Systems" onclick="location.href='save.html?step=1'" />
<input type="button" name="loadButton" value="Load Systems" onclick="location.href='load.html?step=1'" />

I looked up how to access GET variables in vbscript and every place I looked said to use Request.QueryString("variableName")

So in my save.html page I'm trying to first print the value of step, just to make sure I'm getting it, before I start actually handling all my code. This is where I'm hung up.

<script type="text/vbscript">
        document.write("<p>in the script<br>")
        document.write("stepVar = ")
        stepVar = Request.QueryString("step")
        document.write(stepVar)
        document.write(stepVar & "</p>")
</script>

... (rest of the page)

(I tried 2 different print statements just in case I was concatenating incorrectly, but neither work.) When I click my save button on the main page, leading me to save.html?step=1, it prints

in the script
stepVar = 
(rest of the page)

So I guess step is coming back null? Is the reason this isn't working because I didn't submit my variable through a form? That shouldn't have anything to do with it... right? Why am I not getting my variable / how can I get the value of "step" so that I can take different actions depending on the value of my variable?

+3  A: 

Request.QueryString is for VBScript in an ASP page (or VB.net in an ASP.net page) that gets executed on the server, not in the clients browser.

If you have a correctly configured web server the following saved as a .asp page would output what you expect (the server is executing everything inside the <% %> block);

<%@LANGUAGE="VBSCRIPT"%>
<%
        response.write("<p>in the script<br>")
        response.write("stepVar = ")
        stepVar = Request.QueryString("step")
        response.write(stepVar)
        response.write(stepVar & "</p>")
%>

(If you wanted to do this in the client web browser you could use location object, here is a js example, which unlike VBScript will work in any browser)

Alex K.
Thanks, this should be a good start... I know it's strange that I'm using VBScript and not working with ASP, but it's because I'm coding a gui tool for AGI's STK. I think I should be able to use javascript for the interface part, so maybe I'll do that instead.
Lauren
A: 

You can use client script to access this value. This question addresses a similar topic:

http://stackoverflow.com/questions/901115/get-querystring-with-jquery

Chris Farmer
A: 

Had to write a function to parse the URL. Seen several of these in javascript, but the only one I found written in VBScript didn't use regular expressions and DIDN'T WORK. After getting sick of trying to get the function to compile, and then to spit out an answer, I decided to write my own function using regular expressions, much like the javascript functions I'd seen (including the ones linked to in the other responses to this question).

So that no one ever has to do this again:

Function GetParameterFromURI(sVarName)

    Dim oTempParamCollection, I, sTempString, sURI_Query
    sURI_Query = window.location.search

    Set myRegExp = New RegExp
    myRegExp.IgnoreCase = False
    myRegExp.Global = False
    myRegExp.Pattern = "(\?|&)" & sVarName & "=[a-zA-Z0-9]+"

    Set matchCollection = myRegExp.Execute(sURI_Query)

    Set match = matchCollection.Item(0)

    returnString = Mid(match.value, InStr(match.value, "=")+1, len(match.value))

    GetParameterFromURI = returnString

End Function

If you use Option Explicit you will have to make sure everything is Dim'd before this will work. I didn't bother.

I encourage reposting of this code if anyone else is in need of this functionality; I'm frustrated that something so simple caused me so much grief and wouldn't wish it on anyone else!

Lauren