Onkeyup = "this.value = this.value.replace (/, / g, '.')" With php echo ''

The input field must be replaced by . .

With HTM, this code works onkeyup="this.value = this.value.replace(/,/g,'.')"

But you need to use in php (with echo) as follows:

 echo '<input type="text" name="amount_1" onkeyup="this.value = this.value.replace(/,/g,'.')" style="width:53px;"></input>'; 

It doesn’t work with php. If you use this this.value.replace(/,/g,/./) , Then , is replaced by /./ .

I tried (/,/g,"/./") , (/,/g,/"."/) , (/,/g,.) nothing works (I mean , doesn’t change to . ).

Any ideas?

+4
source share
1 answer

You need to escape the backslash in your PHP code.

 echo '<input type="text" name="amount_1" onkeyup="this.value = this.value.replace(/,/g,\'.\')" style="width:53px;"></input>'; 

Otherwise, you cut your line in pices and put it along with a dot.

+6
source

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


All Articles