0

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.

Calvin Nunes
  • 6,376
  • 4
  • 20
  • 48
public9nf
  • 1,311
  • 3
  • 18
  • 48
  • [Duplicate](https://stackoverflow.com/questions/4292914/javascript-url-decode-function/4458580) – Adder Feb 01 '19 at 15:31
  • Possible duplicate of [JavaScript URL Decode function](https://stackoverflow.com/questions/4292914/javascript-url-decode-function) – Daniel Beck Feb 01 '19 at 15:32

1 Answers1

1

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.