Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
178
rated 0 times [  185] [ 7]  / answers: 1 / hits: 82190  / 12 Years ago, mon, august 27, 2012, 12:00:00

Possible Duplicate:

jQuery / Javascript replace <space> in anchor link with %20




I am getting sParameter like this :


sParameter = document.getElementById('ddParameterType').value;


If I am getting word like "Test - Text" as the ddParameterType item, then I am replacing the space in word like below:


sParameter = document.getElementById('ddParameterType').value.replace("","%20");


but it is returning a valur like %20Test - Text.
I need like Test%20-%20Text.


More From » javascript

 Answers
15
sParameter = encodeURIComponent(sParameter.trim()) //Test%20-%20Text


the .trim will remove leading and trailing whitespace from the string. encodeURIComponent will URL-encode it.


[#83405] Saturday, August 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaylynkarinam

Total Points: 740
Total Questions: 103
Total Answers: 103

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
;