Zero to right - Input

Asked

Viewed 244 times

-1

Good afternoon,

I have an input text that only receives number, I need that in the act in which the user type a value, then add the number zero to the right, could help me?

  • 1

    Only the first time or every time the user enters a number?

  • Friend every time he enters a value...

  • Something like this: https://jsfiddle.net/b15p4f5e/ ?

2 answers

1

var input = document.querySelector('#meuInput');
input.addEventListener('keyup', function() {
    this.value = this.value + 0;
});

The idea is: every time a key is dropped, the value of the input should receive a 0 in the end.

Online example: https://jsfiddle.net/b15p4f5e/

  • The problem of this idea ai is that as soon as the user type 1 character he already implements a zero in front, and if in case the user wants to type a value with 3 decimal places for example...

  • @Marzine hence my question "Only the first time or every time the user enters a number". So you want to insert a zero, just once, on the right?

0

  • While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. For example, how to implement this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.