PDA

View Full Version : formating text in querystring


BarrMan
12-18-2005, 07:05 PM
i have this link http://localhost/trivia/trivia.asp?q=%22hello%22 which i want my input form to contain the word "hello", but i don't get there anything.
i tried using this function:
Function quoteReplace(str)
If IsEmpty(str) Or IsNull(str) Then Exit Function
str = Replace(str,"%22",""")
quoteReplace = str
End Function
and then:
<form method="post" action="addq.asp" id=form1 name=form1>
Question: <input size="100" type="text" name="q" value="<%=quoteReplace(Request.QueryString("q"))%>"><br>
Answer: <input type="text" size="100" name="a"><br><br>
<input type="submit" value="add question" id=submit1 name=submit1>
</form>
But it's still returning a blank input to me.

btw: the %22 is: "

Thanks.

miranda
12-19-2005, 01:47 AM
that is because if you view the source you will see the following

<input size="100" type="text" name="q" value=""hello"">


So your function is not working like you think it is.
Where you are erring is that the %22 is urlEncoded yes it means " but, when when you do a Response.Write request.Querystring("q") it will not dispaly as %22hello&22 instead it will dispalay as "hello" . So how to solve your problem and fix your function? simple replace the %22 in the replace function with two double quotes like so ""

so instead of
str = Replace(str,"%22","&quot;")

use this
str = Replace(str,"""","&quot;")

your function will work now.

BarrMan
12-19-2005, 06:32 AM
Thanks that helped!

glenngv
12-19-2005, 08:19 AM
You don't need to manually replace symbols to its HTML equivalent. Server.HTMLEncode method already does that.

<input size="100" type="text" name="q" value="<%=Server.HTMLEncode(Request.QueryString("q"))%>">

BarrMan
12-21-2005, 09:50 AM
wow! it really replace all the regular chars to html chars??
Thanks very very much!