如何在选择时选择其他选项时不断增加?如果我选择相同的选项,则恒定增量将起作用

问题描述 投票:0回答:0
$.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("");
        }
    });

选择任何选项时一致增量

jquery ajax
© www.soinside.com 2019 - 2024. All rights reserved.