View Full Version : requesting querystring %
christrinder
04-10-2003, 01:06 PM
Hello,
Why is nothing ever simple?!!! I'm using a querystring to carry a percentage figure through to a popup window. However, when I come to display it, I get an error... I have established that it is the % symbol causing the problem, but rather than not use one, I would like to find a solution to this ickle problem. Any ideas? One thought I had (not sure if it would work) was to put ' ' either side of the percentage value... but this has a problem because I'm already inside two ' '. The line of code I'm using can be seen below, where [objRSbench("sec3_2b")] = 90%
OnClick="javascript:popup('detail.asp?s=3&ss=2&kpi=<% = objRSbench("sec3_2b") %>')"
Thanks for your help.
Chris
glenngv
04-10-2003, 01:30 PM
onclick="javascript:popup('detail.asp?s=3&ss=2&kpi=<% = Server.URLEncode(objRSbench("sec3_2b")) %>')"
glenngv
04-10-2003, 01:54 PM
http://www.devguru.com/Technologies/asp/quickref/server_urlencode.html
info from helpfile
---------
URLEncode
The URLEncode method applies URL encoding rules, including escape characters, to a specified string.
Syntax
Server.URLEncode( string )
Parameters
string
Specifies the string to encode.
Example
The following script
<%Response.Write(Server.URLEncode("http://www.microsoft.com")) %>
produces the output
http%3A%2F%2Fwww%2Emicrosoft%2Ecom
posts crossed.
Didn't work? Must try that.
Easiest sollution, cut of the percentage sign and add it back on if necessary on the next page.
glenngv
04-10-2003, 01:58 PM
try running this:
response.write(server.urlencode("100%"))
you should get:
100%25
where %25 is the encoded value of %
I need to be able to use them in a querystring, to pull out and write out in a paragraph on another page. Any other ideas?
Like i said, have to try the urlencode thing. Can't imagen it not working.
I don't understand why it needs to be in the querystring. You can post the form and get the value with request.form and write it out like as if it was in the querystring.
I alway post inputform (unless i post it to a page that can be requested by other pages that have the values in a querystring (dynamically generated links and so). But this is quite rare.
christrinder
04-10-2003, 03:08 PM
Sorry, I edited my post obvioulsy after you replied. It does work, I misunderstood its use before. I encode the input to the db, but when I call it back on another page, it's still 100%25. How do I then get rid of the 25?
Thanks,
Chris
variable=replace(variable,"%25","%")
or chop of the 25 (buth replace is safer)
variable=left(variable,(Len(variable)-2))
christrinder
04-10-2003, 03:49 PM
Thanks Raf,
But how do I use that on the follow...
<input type="text" value='"& request.querystring("kpi") &"'>
<input type="text" value=" <% replace(request.querystring("kpi"),"%25","%") %>">
Spudhead
04-10-2003, 04:08 PM
I've never understood this urlEncode thing.
I ALWAYS use escape() - passing data via querystring, dropping strings into a database, even just posted form data - just for the sheer fun of it :)
You escape() it when it goes in, and you unescape() it when it comes out. No percentages, no single quotes, no screwed up data or pages that mysteriously stop working; just two simple functions that do the job. Why the fuss?
glenngv
04-15-2003, 08:15 AM
Originally posted by christrinder
Sorry, I edited my post obvioulsy after you replied. It does work, I misunderstood its use before. I encode the input to the db, but when I call it back on another page, it's still 100%25. How do I then get rid of the 25?
Thanks,
Chris
you don't have to remove the 25. when you do a request.querystring on a parameter with encoded value, the retrieved value would be automatically decoded.
so let's say you have this querystring:
&kpi=100%25
response.write(request.querystring("kpi"))
would write 100%
and don't think that request.querystring will just chopped off 25 in the sample above to decode it. it just so happened that url encoded string consists of the percent symbol + the hex value of the character. the hex value of % is 25, so its encoded value is % plus 25 which is %25. Other sample:
response.write(server.urlencode("blah blah"))
the output will be:
blah%20blah
since the hex value of space is 20.
hope that helps.
glenngv:
when you do a request.querystring on a parameter with encoded value, the retrieved value would be automatically decoded
Didn't know that. Thanks Glenngv:thumbsup:
I know the replace worked (thought it worked) but it probably just didn't replace anything, cause there was nothing to replace.
spudhead:
I've never understood this urlEncode thing. I ALWAYS use escape()
Escape is JS no? Think christrinder uses VBscript + the "URLEncode method applies URL encoding rules, including escape characters, to a specified string" (dixit the helpfile) so i presume it incorporates escape().
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.