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?
Share Improve this question edited Jun 23, 2013 at 6:48 user2465936 asked Jun 23, 2013 at 6:44 user2465936user2465936 1,0404 gold badges17 silver badges32 bronze badges 1- What you mean about "does not work"? Errors or something? – Ionică Bizău Commented Jun 23, 2013 at 6:47
1 Answer
Reset to default 6You 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.