0

Guys i need to fill out an input with zero, to always have 6 characters.
Exemple:
User enters the number 23, while he type, the others 4 characters are 0:

    000000 (start)
000002 (type 2)
000023 (type 3)


I do some searches, but not found and i have no ideia how to do this ;/

1

2 Answers 2

0

One solution possible :

var el = document.getElementById('el');
var updatetext = function(){
  el.value = ('000000' + el.value).slice(-6);
}
  
el.addEventListener("keyup", updatetext , false); 
<input id='el' type = 'text' value='000000'>

Sign up to request clarification or add additional context in comments.

Comments

0

Try like this:

function padSix(x) 
{
  if (x <= 999999) 
  { 
     x = ("00000"+ x).slice(-6); 
  }
  return x;
}

JSFIDDLE DEMO

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.