Hi folks,
I just modified an older code and now nothing seems to be working. Could you please guide where am I going wrong.
Some of the things that aren't working are:
Earlier, focus would always stay on the only input field present on the screen. (Now it doesnt), also the if else conditions in the code arent working. On keyup function isnt working either.
<script language="javascript">
$(document).ready(function() {
$("#serialNumber").focus();
$("#scroll-pane").jScrollPane();
$(document).keydown(function() {
$("#serialNumber").focus();
});
var code = $("#hiddenSerialCode").val();
$("#serialNumber").keyup(function() {
var $this = $(this);
var d = $(this).val();
var d5 = d.substring(0, 5);
if (d.length != 20) {
alert('Incorrect Serial Code');
}
else if (d.length == 20 && d5 != code) {
var serialCode = d.substring(0, 8);
alert('Serial Code: ' + serialCode);
$(this).val("");
}
else if (d.length == 20 && d5 == code) {
var flagNumber = d.substring(0, 6);
var errorNumber = d.substring(7, 10);
alert('Flag Number ' + flagNumber + '\nError Number ' + errorNumber);
$(this).val("");
}
});
});
</script>
HTML Code: --------------
<table>
<tr>
<td>
<input type="text" id="serialNumber" class="" />
<input type="hidden" id="hiddenSerialCode" value="01327"/>
</td>
</tr>
</table>
<div id="scroll-pane" class="scroll-pane">
Old working Code: ------
$(document).ready(function() {
$("#serialCode").focus();
$(document).keydown(function() {
$("#serialCode").focus();
});
$("#serialCode").keyup(function(){
var $this = $(this);
var d = $(this).val();
if (d.length >= 5){
//$this.attr("disabled","disabled")
var $code = d.substring(0,8) ;
alert('code is ' + $code);
}
});
});