In doing a google search for javascript urlencode, I realized I was using that terminology just because I was familiar with the PHP function of the same name. Javascript’s method is actually called encodeURI() which will encode all characters except:
, / ? : @ & = + $ #
But what I really wanted to do was get javascript to convert a string that would be okay to put into a query string of a URL. For this, use encodeURIComponent(). This will convert all characters except alphabetic, decimal digits, and:
- _ . ! ~ * ' ( )
That’s more like it. You can view the complete reference at mozilla or w3schools.




This information was indeed useful. Thanks.
By Alex on Mar 25, 2008
Thank god someone remembered what that method was called
been looking for ages =)
By Floydan on May 6, 2008
Thanks! There are tons of website wrong about this…
At last I found your post that is right !
By Michel on Aug 21, 2008
Glad you found this useful!
By Scott Meves on Aug 21, 2008