I have a form that when submitted to the server will contain commas in the query string values, for example:
test.com/?manufacturer=0&body-style=0&min-price=270%2C000&max-price=780%2C000
Is there a way to remove this comma using JS just after the user clicks the form but before it will be submitted to the server? I have this approach here: How replace query string values using jQuery?
But that will only change the text to integer but in the URL itself. I also tried using input number attribute in HTML 5 but I cannot figure out how to use a comma by default to show it on the form: How to force to display a number with a comma with input type number?
I would appreciate any tips. Thanks.
UPDATE
Final working solution:
$('.my_form').submit(function() {
var x=$('#input_text_field_one').val();
x=x.replace(/,/g,'');
x=parseInt(x,10);
$('#input_text_field_one').val(x);
return true;
});
input_text_field_one is the input text form containing a number with commas. .my_form is the class name for the form. After form submit the above code replace the numbers with commas to without commas. So finally, the numbers are submitted as number. :)
I think you want something like this:-
form.onSubmit = function(){
form.action = form.action.replace(",", "");
return true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With