$.ajax({
url: 'getLastControlNumber.php',
method: 'GET',
success: function(data) {
var lastControlNumber = data.slice(-5)
console.log(lastControlNumber);
var increment = (parseInt(lastControlNumber) + 1).toString().padStart(5, '0');
console.log(increment);
$("#last_control_number").val(lastControlNumber);
},
error: function() {
console.log('Error occurred during AJAX request');
}
});
$("#itemtype, #consigned, #sections").change(function() {
var itemType = $("#itemtype option:selected").val() || "";
var consigned = $("#consigned option:selected").val() || "";
var sections = $("#sections option:selected").val() || "";
if (itemType !== "" && consigned !== "" && sections !== "") {
$('#submit').attr('disabled', false);
var currentDate = new Date();
var currentMonth = currentDate.getMonth();
var currentYear = new Date().getFullYear();
var lastControlNumber = parseInt($('#last_control_number').val()) || 0;
var controlNumberValue = itemType + getValueFromMonth(currentMonth) + currentYear.toString().substr(-2) + sections + consigned + (lastControlNumber + 1).toString().padStart(5, '0');
$("#control_number").val(controlNumberValue);
console.log(controlNumberValue);
$("#month").val(getMonthName(currentMonth));
$("#year").val(currentYear);
} else {
$('#submit').attr('disabled', true);
$("#control_number").val("");
}
});
选择任何选项时一致增量