PDA

View Full Version : Resolved Retrieve URL variable in hidden field using VBScript


nicky
07-09-2010, 03:19 PM
I have a dynamic URL that I need to retrieve the variable from and insert it into a hidden form field using VBScript.

Let's pretend the URL is www.mydomain.com/form.php?location=anytown

I need to retrieve the variable from location

My input is:

<input type="hidden" name="input1" value=""/>

I tried:

<input type="hidden" name="input1" value="<% Request.QueryString("location") %>"/>

... However, it didn't work, and I believe including the double quotations around location set it off, yet it won't work with single quotes or without any.

Any solutions? I appreciate all help.

Old Pedant
07-09-2010, 07:06 PM
Your code looks right to me.

Let's debug.


<%
loc = Trim(Request.QueryString("location"))
Response.Write "Value from query string is " & loc & "<hr>" & vbNewLine
%>
<form>
<input type="text" name="input1" value="<%=loc%>" />
</form>

That is, first of all get the value and dump it out via Response.Write, to make sure it is there.

Then dump it into a *NON*-hidden form field, to make sure that works.

As the FINAL step, after the above works, you can change to

<%
loc = Trim(Request.QueryString("location"))
%>
<form>
<input type="hidden" name="input1" value="<%=loc%>" />
</form>

nicky
07-09-2010, 07:21 PM
It worked! Thanks a bunch :)

One of the reasons it probably didn't work was because the page was a .php extension.

Old Pedant
07-09-2010, 07:54 PM
One of the reasons it probably didn't work was because the page was a .php extension.

ONE of the reasons??? ONE?

LOL!!

You know, in PHP you could do

<input type="text" name="whatever" value="<?php echo $_REQUEST["location"]; ?>" />


So nearly the same thing.

nicky
07-09-2010, 07:56 PM
I had that, and it wasn't grabbing the location. It did when then page I'm sending the form to was in PHP, but when I converted it to ASP, it stopped working.

Since you've been a big help, do you think you can take a look at my other post? *searches for thread* Ah... I see you've already beat me there lol.