Im trying to build a dynamic input box. When I click on the numpad I want it to show on the box, and limit that box to one number. When it reaches its limit the next input would go to the next box.
I dont want the user to able to click and manually enter a value on the input box, i just want them to use the numpad. Is the input box a good solution to this?
Here's my code:
https://jsfiddle.net/Piq9117/dwxt928c/
This code puts the number that I clicked on all the boxes. How do I write it so it will go to the other box when the box already has a number?
$(function () {
var $passBox = $('input[type="text"]');
var $numpad = $('.numpad');
$numpad.on('click', function () {
var $numValue = $(this).text();
$passBox.val($numValue);
})
});
DEMO
<div class="passcode">
<div class="passcodeBox">
<ul>
<li><input type="text" readonly></li>
<li><input type="text" readonly></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<table>
<tbody>
<tr>
<td class="numpad">1</td>
<td class="numpad">2</td>
<td class="numpad">3</td>
</tr>
<tr>
<td class="numpad">4</td>
<td class="numpad">5</td>
<td class="numpad">6</td>
</tr>
<tr>
<td class="numpad">7</td>
<td class="numpad">8</td>
<td class="numpad">9</td>
</tr>
<tr>
<td></td>
<td class="numpad">0</td>
</tr>
</tbody>
</table>
</div>
Add attr readonly in input
Make your input fields as readonly, then replace the following script, you ll get result as you expected.
$(function() {
var $numpad = $('.numpad');
var n=0;
$numpad.on('click', function() {
var $passBox = $('input[type="text"]:eq('+n+')');
n=n+1;
if(n>1)
n=0;
var $numValue = $(this).text();
$passBox.val($numValue);
});
});
DEMO
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