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?
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:
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!