When I type the last number in, the first number goes inside the text-box
(it disappears), it's adding one extra space.
After I click outside the text-box
it looks good which I need during typing last character.
#number_text {
padding-left: 9px;
letter-spacing: 31px;
border: 0;
background-image: linear-gradient(to right, #e1e1e1 70%, rgba(255, 255, 255, 0) 0%);
background-position: left bottom;
background-size: 38px 1px;
background-repeat: repeat-x;
width: 220px;
box-sizing: border-box;
outline:none;
}
<input type="text" id="number_text" maxlength="6" pattern="\d{6}" value="1234" >
Help me to get out from this issues. Thanks
The standard solution to restrict a user to enter only numeric values is to use <input> elements of type number. It has built-in validation to reject non-numerical values.
The E stands for the exponent, and it is used to shorten long numbers. Since the input is a math input and exponents are in math to shorten great numbers, so that's why there is an E.
Answer: Use the value Property You can simply use the value property of the DOM input element to get the value of text input field. The following example will display the entered text in the input field on button click using JavaScript.
You can use the <input> tag with attribute type='number'. This input field allows only numerical values. You can also specify the minimum value and maximum value that should be accepted by this field.
Add space for another number and clip the input using clip-path
#number_text {
padding-left: 9px;
letter-spacing: 31px;
border: 0;
background:
repeating-linear-gradient(to right, #e1e1e1 0 26px, transparent 26px 38px)
bottom/100% 1px no-repeat;
width: 260px;
clip-path:polygon(0 0, calc(100% - 38px) 0, calc(100% - 38px) 100%, 0 100%);
box-sizing: border-box;
outline: none;
}
<input type="text" id="number_text" maxlength="6" pattern="\d{6}" value="1234">
Or without clip-path by reducing the background-size:
#number_text {
padding-left: 9px;
letter-spacing: 31px;
border: 0;
background:
repeating-linear-gradient(to right, #e1e1e1 0 26px, transparent 26px 38px)
bottom left/calc(100% - 38px) 1px no-repeat;
width: 260px;
box-sizing: border-box;
outline: none;
}
<input type="text" id="number_text" maxlength="6" pattern="\d{6}" value="1234">
Use this code. its nicely work
var container = document.getElementsByClassName("wrap")[0];
container.onkeyup = function(e) {
var target = e.srcElement;
var maxLength = parseInt(target.attributes["maxlength"].value, 6);
var myLength = target.value.length;
if (myLength >= maxLength) {
var next = target;
while (next = next.nextElementSibling) {
if (next == null)
break;
if (next.tagName.toLowerCase() == "input") {
next.focus();
break;
}
}
}
else if (myLength <= maxLength)
{
prev=target.previousElementSibling;
while (prev = prev) {
if (prev == null)
break;
if (prev.tagName.toLowerCase() == "input") {
prev.focus();
break;
}
}
}
}
.wrap input {
border-top: 0;
border-left: 0;
border-right: 0;
border-bottom: 1px solid #000;
width: 3%;
display: inline-block;
outline: 0;
text-align: center;
}
<div class="wrap">
<input type="text" maxlength="1" />
<input type="text" maxlength="1" />
<input type="text" maxlength="1" />
<input type="text" maxlength="1" />
<input type="text" maxlength="1" />
<input type="text" maxlength="1" />
</div>
Try to add this script bellow the input-field:
<script>
var oInput = document.getElementById('number_text');
oInput.onkeypress = function(ev) {
setTimeout(function() {
if( oInput.value.length > 5 ) {
oInput.setSelectionRange(0,0);
oInput.blur();
}
}, 0);
}
</script>
This one forces your input-cursor to the beginning of the input after the 6th character was entered. I also added a blur() to the field so the cursor-jump to the beginning won't stick out.
The timeout is also needed. Without it the entered character will be inserted at the beginning. More about timeout: Is setTimeout a good solution to do async functions with javascript?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With