How to remove comma in input text form using JS before it is sent to server?

I have a form that when sent to the server will contain commas in the query value strings, 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 right after the user clicks on the form, but before it is submitted to the server? I have an approach like this: How to replace query string values ​​with jQuery?

But this will only change the text to an integer, but in the URL itself. I also tried using the number input attribute in HTML 5, but I can’t figure out how to use the default comma to show it in the form: How do I get the number to display with a comma with the input type number?

I would be grateful for any advice. 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 a text input form containing a number with commas. .my_form is the class name for the form. After the form, submit the above code, replace the numbers with commas without commas. So finally, the numbers are presented as a number. :)

+4
source share
1 answer

I think you want something like this: -

 form.onSubmit = function(){ form.action = form.action.replace(",", ""); return true; } 
+2
source

Source: https://habr.com/ru/post/1488481/


All Articles