In input field need to replace ,
with .
.
With HTM such code is working onkeyup="this.value = this.value.replace(/,/g,'.')"
But need to use in php (with echo) like this:
echo '<input type="text" name="amount_1" onkeyup="this.value = this.value.replace(/,/g,'.')" style="width:53px;"></input>';
With php does not work. If use this this.value.replace(/,/g,/./)
then ,
is replaced with /./
.
Tried (/,/g,"/./")
, (/,/g,/"."/)
, (/,/g,.)
nothing works (I mean ,
does not change to .
).
Any ideas?
In input field need to replace ,
with .
.
With HTM such code is working onkeyup="this.value = this.value.replace(/,/g,'.')"
But need to use in php (with echo) like this:
echo '<input type="text" name="amount_1" onkeyup="this.value = this.value.replace(/,/g,'.')" style="width:53px;"></input>';
With php does not work. If use this this.value.replace(/,/g,/./)
then ,
is replaced with /./
.
Tried (/,/g,"/./")
, (/,/g,/"."/)
, (/,/g,.)
nothing works (I mean ,
does not change to .
).
Any ideas?
You have to escape the '
with a 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 are cuting your string into to pices an put it together with the point.