I have a problem, my source url is as follows:
test.com/?manufacturer=0&body-style=0&min-price=270%2C000&max-price=780%2C000
As you can see, the minimum price and maximum price values โโin the query string are incorrect due to the comma that is passed to the URL. It should be in their corresponding integer value, such as min-price = 270000 and max-price = 780000.
I need to convert the query string values โโmin-max and max-price using jQuery. I am not currently doing this. But I have codes to get them from the url and then convert them to the correct value. I just don't know how to implement them back to a URL (like a new URL) using jQuery. These are my existing codes:
//Function to get value of parameter in query string function getParameterByName(name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } //Function to remove commas and convert to number function convert_to_pure_number(x) { //Remove commas var x_withoutcommas=x.replace(/,/g,''); //Convert to plain number var y =parseInt( x_withoutcommas ,10); return y; } var min_price_original=getParameterByName('min-price'); var max_price_original=getParameterByName('max-price'); var min_price_converted=convert_to_pure_number(min_price_original); var max_price_converted=convert_to_pure_number(max_price_original);
Any suggestions, how do I continue the above code with extra code to return them to the url? Thanks for any help.
UPDATE This is the process: The form will be sent to the server โ the URL will contain commas โ My new code will remove the comma โ The correct value will be used in the line of the query string.
Greetings.
source share