[Javascript] Replacing special characters in query string in javascript

Rajaram Sahasranaman rajarsn at gmail.com
Thu Apr 5 00:41:33 CDT 2007


Thank you very much Nick, it's working in the desired manner. Thanks a
lot!!!

On 4/4/07, Nick Fitzsimons <nick at nickfitz.co.uk> wrote:
>
> On 4 Apr 2007, at 12:14:58, Rajaram Sahasranaman wrote:
>
> > I have a peculiar problem in my application. I have a query string
> > in javascript which I have to pass the Team Name to the next page.
> > Everything is working fine, but suddenly there is a problem occurs
> > now. That is, if there is any ampersand character in the team name,
> > it is not taking the characters after that.
> >
> > For eg: the team name can be Printing & Stationery. So the query
> > string will take upto Printing and avoid after that. How to add
> > these special character along with he query string in javascript?
>
> The ampersand is one of a number of reserved characters within the
> query component of a URI, as described in section 3.4 of RFC 2396
> <http://www.ietf.org/rfc/rfc2396.txt>.
>
> To correctly encode your query string data, use the
> encodeURIComponent function:
>
> var queryComponent = "Printing & Stationery";
> alert(encodeURIComponent(queryComponent)); // shows "Printing%20%26%
> 20Stationery"
>
> Regards,
>
> Nick.
> --
> Nick Fitzsimons
> http://www.nickfitz.co.uk/
>
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20070405/bdb5c264/attachment.htm>


More information about the Javascript mailing list