Friday, March 16, 2012

Passing an '&' as part of the parameter's value in a query string

I have a situation where I will collect text from a textbox and pass that
text as one of the parameters in another pages query string. the problem is
that if the user types in a '&' as part of the text message, the page being
called thinks the '&' is parsing out another parameter. Using JavaScript,
what should I do to pass the entire message in the query string?

Thanks.

--
moondaddy@dotnet.itags.org.newsgroup.nospammoondaddy wrote:

Quote:

Originally Posted by

I have a situation where I will collect text from a textbox and pass that
text as one of the parameters in another pages query string. the problem is
that if the user types in a '&' as part of the text message, the page being
called thinks the '&' is parsing out another parameter. Using JavaScript,
what should I do to pass the entire message in the query string?
>
Thanks.


Use the encodeURIComponent function to encode the value that you put in
the URL.

You should do this for any values that you put in an URL that might
contain characters that needs encoding.

--
Gran Andersson
_____
http://www.guffa.com
On Sep 12, 9:19 am, "moondaddy" <moonda...@.newsgroup.nospamwrote:

Quote:

Originally Posted by

I have a situation where I will collect text from a textbox and pass that
text as one of the parameters in another pages query string. the problem is
that if the user types in a '&' as part of the text message, the page being
called thinks the '&' is parsing out another parameter. Using JavaScript,
what should I do to pass the entire message in the query string?
>


& = %26
Alexey Smirnov wrote:

Quote:

Originally Posted by

On Sep 12, 9:19 am, "moondaddy" <moonda...@.newsgroup.nospamwrote:

Quote:

Originally Posted by

>I have a situation where I will collect text from a textbox and pass that
>text as one of the parameters in another pages query string. the problem is
>that if the user types in a '&' as part of the text message, the page being
>called thinks the '&' is parsing out another parameter. Using JavaScript,
>what should I do to pass the entire message in the query string?
>>


>
& = %26
>


That is correct, but that only solves the problem with that specific
character. There are several other characters that are not valid in a
value in a query string, like spaces for example.

--
Gran Andersson
_____
http://www.guffa.com
Thanks!

encodeURIComponent worked perfect.

"Gran Andersson" <guffa@.guffa.comwrote in message
news:uFyGU9Q9HHA.980@.TK2MSFTNGP06.phx.gbl...

Quote:

Originally Posted by

moondaddy wrote:

Quote:

Originally Posted by

>I have a situation where I will collect text from a textbox and pass that
>text as one of the parameters in another pages query string. the problem
>is that if the user types in a '&' as part of the text message, the page
>being called thinks the '&' is parsing out another parameter. Using
>JavaScript, what should I do to pass the entire message in the query
>string?
>>
>Thanks.


>
Use the encodeURIComponent function to encode the value that you put in
the URL.
>
You should do this for any values that you put in an URL that might
contain characters that needs encoding.
>
--
Gran Andersson
_____
http://www.guffa.com

0 comments:

Post a Comment