Problem with querystring

M

MikeR

Hello -
I pass an item to an asp page as a query string. The value has a space in it. On the
receiving page, the value displays fine just as a variable, but if I use it to pre-fill an
input box, only the first word displays.
Ex:
The URL- http://myserver.com/test.asp?Item=Blue Vase

The page
<http>
<body>
<form name="form1" method="POST" action="mailto:[email protected]">
<p>Product: <%=request.querystring("item")%> <===shows Blue Vase
<input name="prod" type=text size="50" value=<%=request.querystring("item")%>> <== shows Blue
<input type="submit" name="Submit" value="Send">
</p>
</form>
</body>
</http>

Thanks,
Mickey
 
C

Chris Hohmann

MikeR said:
Hello -
I pass an item to an asp page as a query string. The value has a space in
it. On the receiving page, the value displays fine just as a variable, but
if I use it to pre-fill an input box, only the first word displays.
Ex:
The URL- http://myserver.com/test.asp?Item=Blue Vase

The page
<http>
<body>
<form name="form1" method="POST" action="mailto:[email protected]">
<p>Product: <%=request.querystring("item")%> <===shows Blue Vase
<input name="prod" type=text size="50"
value=<%=request.querystring("item")%>> <== shows Blue
<input type="submit" name="Submit" value="Send">
</p>
</form>
</body>
</http>

Thanks,
Mickey

You need to place the value attribute of the input tag in quotes. It would
probably be a good idea to html encode the value just in case the value
itself contains literal quotes. I've also taken the liberty of quoting the
other attributes of the input tag.

<input name="prod" type="text" size="50"
value="<%=Server.HTMLEncode(Request.Querystring("item"))%>">
 
M

MikeR

Thanks Chris -
Works as expected.
Mickey

Chris said:
You need to place the value attribute of the input tag in quotes. It would
probably be a good idea to html encode the value just in case the value
itself contains literal quotes. I've also taken the liberty of quoting the
other attributes of the input tag.

<input name="prod" type="text" size="50"
value="<%=Server.HTMLEncode(Request.Querystring("item"))%>">
 
B

Bullschmidt

Perhaps this may hopefully give you some ideas:

Classic ASP Design Tips - QueryString
http://www.bullschmidt.com/devtip-querystring.asp

Example URL with a querystring:
http://www.mysite.com/mypg.asp?Category=Baseball

Because a variable might contain some odd characters like spaces, it's
usually a good idea to use Server.URLEncode when creating a querystring
from a variable:
<a href="http://www.mysite.com/mypage?Category=<%=
Server.URLEncode(objRS("Category")) %>">objRS("Category")</a>

And in the page that is opened you can use
Request.QueryString("Category") to get the value of Category.

Category = Request.QueryString("Category")

' Set strSQL.
strSQL = "SELECT * FROM MyTable WHERE"
strSQL = strSQL & " (Category='" & Category & "')"
strSQL = strSQL & " ORDER BY Subcategory"

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...

<<
Hello -
I pass an item to an asp page as a query string. The value has a space
in it. On the
receiving page, the value displays fine just as a variable, but if I use
it to pre-fill an
input box, only the first word displays.
Ex:
The URL- http://myserver.com/test.asp?Item=Blue Vase

The page
<http>
<body>
<form name="form1" method="POST" action="mailto:[email protected]">
<p>Product: <%=request.querystring("item")%> <===shows Blue Vase
<input name="prod" type=text size="50"
value=<%=request.querystring("item")%>> <== shows Blue
<input type="submit" name="Submit" value="Send">
</p>
</form>
</body>
</http>

Thanks,
Mickey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,835
Members
47,383
Latest member
EzraGiffor

Latest Threads

Top