Reputation: 1399
I use the following code to get GET
values from a URL an use them in my jQuery script.
URL-example: www.example.com/de/product&print=1?option=0?money=CHF%20%202680.%E2%80%93
/* GET VALUES TO SELECT OPTION */
jQuery.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}
/* GET MONEY VALUE */
var money = jQuery.urlParam('money');
console.log(money);
I can get the value money with this code but how can I transform it to "normal-text". The value should be "CHF 2680.-" and not "CHF%20%202680.%E2%80%93"
so that I can use it in javascript.
Upvotes: 0
Views: 189
Reputation: 11
There is a global function decodeURI()
in javascript that takes care of encoded text.
Usage:
var money = jQuery.urlParam('money');
var decodedMoney = decodeURI(money)
console.log(decodedMoney);
decodeURI()
replaces each escape sequence in the encoded URI with the actual character that it represents.
Upvotes: 1