最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - onkeyup="this.value = this.value.replace(,g,'.')" with php echo' &#39

matteradmin8PV0评论

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
Add a ment  | 

1 Answer 1

Reset to default 6

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.

Post a comment

comment list (0)

  1. No comments so far