最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to remove comma in the input text form using JS before it will be submitted to the server? - Stack Overflow

programmeradmin0浏览0评论

I have a form that when submitted to the server will contain mas in the query string values, for example:

 test/?manufacturer=0&body-style=0&min-price=270%2C000&max-price=780%2C000

Is there a way to remove this ma 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 ma by default to show it on the form: How to force to display a number with a ma 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 mas. .my_form is the class name for the form. After form submit the above code replace the numbers with mas to without mas. So finally, the numbers are submitted as number. :)

I have a form that when submitted to the server will contain mas in the query string values, for example:

 test./?manufacturer=0&body-style=0&min-price=270%2C000&max-price=780%2C000

Is there a way to remove this ma 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 ma by default to show it on the form: How to force to display a number with a ma 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 mas. .my_form is the class name for the form. After form submit the above code replace the numbers with mas to without mas. So finally, the numbers are submitted as number. :)

Share Improve this question edited May 23, 2017 at 12:12 CommunityBot 11 silver badge asked Jun 27, 2013 at 11:51 Emerson ManingoEmerson Maningo 2,2799 gold badges33 silver badges48 bronze badges 3
  • what's the problem exactly ? why can't you just take care of the eventual mas server-side ? What if at some point the value after the ma is not 0 ? – Laurent S. Commented Jun 27, 2013 at 11:55
  • Yes this is easy server side but it's a plugin that is beyond my control. I don't want to edit the plugin core source code because I'm not allowed. And there are no hooks to override. – Emerson Maningo Commented Jun 27, 2013 at 12:05
  • Final solution that works I posted it on my question.. – Emerson Maningo Commented Jun 27, 2013 at 12:39
Add a ment  | 

1 Answer 1

Reset to default 5

I think you want something like this:-

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论