I'm trying to work out how to increase a weird record numbering system I think I'm on the right track but is there a better way?
The record numbering works like this member number - year - 4 digit number e.g. 1076-14-0081
I need to increase the 0081 part of the number to be the next number.
When I load the input form up I call in the last number to a text field animalId and focus on the text field. Once they exit out of the field the code below is run and the field is updated.
$(function() {
$("#animalId").focusout(function() {
curNum = $("#animalId").val();
animalIDArray = curNum.split('-');
memberNumber = animalIDArray[0];
var year = Number(animalIDArray[1]);
animalNumber = Number(animalIDArray[2]);
animalNumber = animalNumber +1;
animalNumber = String("0000" + animalNumber).slice(-4);
result = [memberNumber, year, animalNumber].join("-");
$("#animalId").val(result);
});
});
I was wondering have I done it correctly or is there a better way I can do this automatically?