1

Please let me know in comments if Im not explaining good.

As the question title says everything can you please tell me how can I decode the dollar sign($) as it goes to %24 in url when submited from the page like you can use this link for example.

http://mubisoft.fh2web.com/Kayak/submit.html

try submiting data and it will get the data from url and will try to populate the input field again but when it tries to get data from url it take %24 with it instead of $ sign.

here is the code of javascript that im using in it.

var url = window.location.href;
    var input = $( "#one" );
    var input2 = $( "#two" );
    if(url.indexOf("?") >= 0){
var params = url.split('?');
var params1 = params[1].split('&');
var a  = params1[0].split('=');
var r = a[1];
var a  = params1[1].split('=');
    input2.val(a[1]);
    input.val(r); // here are populating data getting from url
}
    $( "#one" ).blur(function() {
        if(input.val().substring(0,1) == '$'){
            return false;
        }else{
            input.val( "$ "+input.val() )
        }
    });
mubashermubi
  • 8,846
  • 4
  • 16
  • 30

2 Answers2

1

Run your encoded string through this function:

decodeURIComponent( encodedString );

Full code for getting variables out of the querystring and decoding:

//this code executes immediately and pulls all the variables
var QueryString = function () {
  var query_string = {};
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    pair[1] = decodeURIComponent( pair[1] ); //encoded characters are decoded here
    if (typeof query_string[pair[0]] === "undefined") {
      query_string[pair[0]] = pair[1];
    }
  } 
    return query_string;
} ();

//then you can access the querystring variables like this
QueryString.varName
JRulle
  • 7,448
  • 6
  • 39
  • 61
0

Given that decodeURI doesn't decode the dollar sign ($), you should use a .replace():

var myURL = 'www.somesite.com/somepage.php?price=%2420';

myURL = myURL.replace(/%24/g,'$'); // www.somesite.com/somepage.php?price=$20
Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
  • Alternately, `encodeURIComponent()` does encode the dollar sign ($) as "%24" so you could use `decodeURIComponent()` to unencode it – JRulle Aug 01 '14 at 19:40