Login Register

URL Encode?

[editor: moving to the appropriate forum…]

Hi. I need to convert "123 Street St., 12345" to a format that is safe for QueryString. For this specific example, it is a simple matter of replacing spaces (" ") with pluses ("+"), but there are other rules.

* Do I have the terminology right? Encoding for QueryStrings is called "URL encoding"?

* Does Dojo have a function to do this?

* I found (with difficulty) dojox.dtl.filter.strings.urlencode() but when I tried using it (first I put dojox.dtl.filter.strings in the require section at the top) I got the strange error in FireBug "TypeError: _7.slice is not a function". Maybe I'm doing something wrong? Below is my code:

dojo.require("dojox.dtl.filter.strings");   //For URL-encode
        function locate() {
            var userAddress = dojox.dtl.filter.strings.urlencode(dojo.byId("address"));
        }

I'm using Dojo 1.2.

You're passing into the

You're passing into the function a domNode. I believe the function is expecting a string url.

var userAddress = dojox.dtl.filter.strings.urlencode(dojo.byId("address").value);

You can also try using the native Javascript function: encodeURI('urltoencode');

The native JS function

The native JS function encodeURIComponent(dojo.byId("address").value) should be enough.

Doh! That was it! Thanks a

Doh! That was it, FiveFeet! Thanks a bunch!

jBurke, that's even simpler. Thanks!