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

M

moondaddy

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.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

moondaddy said:
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.
 
G

Guest

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
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Alexey said:

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.
 
M

moondaddy

Thanks!

encodeURIComponent worked perfect.


Göran Andersson said:
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.
 

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
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top