views:

141

answers:

1

I'm having problems encoding a string so I can place a variable into a link. I'm sure this is really simple, but i had trouble turning anything up.

$("a.inquiry").attr("href", "/inquiry/6933/text=" + encodeURI("text o"));

This doesn't work.

encodeURI("text o")

Still returns:

link/text o

Instead of:

link/text%20

Also tried:

$("a.inquiry").attr("href", encodeURIComponent("/inquiry/6933/text=" + "text o"));
+3  A: 

Try with encodeURIComponent instead.

Sarfraz
that does work either ;-( either its not working or something else I'm doing is undoing the encoding afterwards?
holden
@holden: It could be so, `encodeURIComponent` has worked for me always.
Sarfraz