Witam
Jestem początkujący w jacaScript i próbuje napisać pewien skrypt. Strona ma działać na tablecie dlatego jest to klawiatura numeryczna + formularz. Problem polega na tym ze po wpisaniu pierwszych czterech cyfr automatycznie skrypt ma nas przenieść do okna następnego i teoretycznie się tak dzieje ale po wciśnięciu kolejnej cyfry pojawiają się one w nowym jaki i w starym oknie. Proszę o pomoc oto kod:
<td><input class="calc" type="button" style="font: 15pt Arial;width:100px; height:50px;" value=1 onclick="pushButton(this.value);"></td> <td><input class="calc" type="button" style="font: 15pt Arial;width:100px; height:50px;" value=2 onclick="pushButton(this.value);"></td> <td><input class="calc" type="button" style="font: 15pt Arial;width:100px; height:50px;" value=3 onclick="pushButton(this.value);"></td> <td><input class="calc" type="button" style="font: 15pt Arial;width:100px; height:50px;" value=4 onclick="pushButton(this.value);"></td> <td><input class="calc" type="button" style="font: 15pt Arial;width:100px; height:50px;" value=5 onclick="pushButton(this.value);"></td> <td><input class="calc" type="button" style="font: 15pt Arial;width:100px; height:50px;" value=6 onclick="pushButton(this.value);"></td> <td><input class="calc" type="button" style="font: 15pt Arial;width:100px; height:50px;" value=7 onclick="pushButton(this.value);"></td> <td><input class="calc" type="button" style="font: 15pt Arial;width:100px; height:50px;" value=8 onclick="pushButton(this.value);"></td> <td><input class="calc" type="button" style="font: 15pt Arial;width:100px; height:50px;" value=9 onclick="pushButton(this.value);"></td> <td><input class="calc" type="button" style="font: 15pt Arial;width:100px; height:50px;" value=0 onclick="pushButton(this.value);"></td> <td><input class="calc" type="button" style="font: 12pt Arial;width:100px; height:50px;" value="WYCZYŚĆ" onclick="pushButton(this.value);"></td>
function pushButton(buttonValue) {
if (buttonValue == 'WYCZYŚĆ') {
document.getElementById('screen').value = '';
document.getElementById('screen2').value = '';
document.getElementById('screen3').value = '';
}
else {
document.getElementById('screen').value += buttonValue;
if(document.getElementById('screen').value.length > 4){
document.getElementById('screen2').focus();
document.getElementById('screen2').value += buttonValue;
}
if(document.getElementById('screen2').value.length > 2){
document.getElementById('screen3').focus();
document.getElementById('screen3').value += buttonValue;
}
}
}
<input type="text" class="calc" id="screen" name="screen" size="3" maxlength="3" value="" /> <input type="text" class="calc" id="screen2" name="screen2" size="3" maxlength="3" value="" /> <input type="text" class="calc" id="screen3" name="screen3" size="4" maxlength="4" value="" /><br />