   jersey_stocks = Product.objects.filter(size__category__name='Jersey')
    category = 'Jersey'
    jersey_list = []
    for jersey in jersey_stocks:
        jersey_info = {
            'size': jersey.size,
            'color': jersey.color,
            'quantity': jersey.quantity,
            'price': jersey.price
        }

        jersey_list.append(jersey_info)

    if request.method == 'POST':
        studentName = request.POST.get('studentName')
        admissionNumber = request.POST.get('admissionNumber')
        type = request.POST.get('issue_category')
        size = request.POST.get("size")
        issue_quantity = request.POST.get("issue_quantity")
        issue_quantity = issue_quantity.strip()
        issue_quantity = int(issue_quantity)
        amount = request.POST.get('amount')
        current_dateTime = datetime.now()

        try:
            stock_issue_calc = calculate_stock_issues(
                request, type, size, issue_quantity)
            item_category = Category.objects.get(name=type)
            item_size = Size.objects.get(name=size)
            current_dateTime = datetime.now()
            random_number = random.randint(10000, 99999)
            bill_number = random_number

            # generated_bill = generate_bill_number(bill)
            # print('+++++++++++++++++++++++++++++++++++++++++++++++++++++')
            # print(bill)

            item_issued = Issued_Item.objects.create(
                category=item_category,
                size=item_size,
                student_name=studentName,
                admission_number=admissionNumber,
                quantity=issue_quantity,
                price=amount,
                date_time=current_dateTime,
                bill_number=bill_number,
            )

            item_issued.save()
            

            issued_current_item = Issued_Item.objects.get(
                bill_number=bill_number)    

            jersey_stocks = Product.objects.filter(size__category__name='Jersey')
            category = 'Jersey'
            jersey_list = []
            for jersey in jersey_stocks:
                jersey_info = {
                    'size': jersey.size,
                    'color': jersey.color,
                    'quantity': jersey.quantity,
                    'price': jersey.price
                }

                jersey_list.append(jersey_info)
            context = { 
                'jersey_stocks ': jersey_stocks,
                'jersey_list': jersey_list,
                'category': category,
                'issued_current_item': issued_current_item,
            }
            # return redirect(request.path) 
            # return render(request, 'print_receipt.html', context=context)
            return render(request, 'add_jersey_stocks.html', context=context)
            # return redirect('print_receipt')
        except:
            messages.error(
                request, f"Issuing of {issue_quantity} nos of {type} from size {size} was failed")
            return redirect(request.path)





            <script>
    document.addEventListener('DOMContentLoaded', function() {
        var categoryField = document.getElementById('id_category');
        var sizeField = document.getElementById('id_size');

        function submitCategoryAndSize() {
            var category = categoryField.value;
            var size = sizeField.value;
            var csrfToken = document.querySelector('[name="csrfmiddlewaretoken"]').value;

            // Create a form element
            var form = document.createElement('form');
            form.method = 'POST';
            form.action = '{% url "your_ajax_url" %}'; // Replace 'your_ajax_url' with the URL name or path

            // Create input elements for category, size, and CSRF token
            var categoryInput = document.createElement('input');
            categoryInput.type = 'hidden';
            categoryInput.name = 'category';
            categoryInput.value = category;
            form.appendChild(categoryInput);

            var sizeInput = document.createElement('input');
            sizeInput.type = 'hidden';
            sizeInput.name = 'size';
            sizeInput.value = size;
            form.appendChild(sizeInput);

            var csrfInput = document.createElement('input');
            csrfInput.type = 'hidden';
            csrfInput.name = 'csrfmiddlewaretoken';
            csrfInput.value = csrfToken;
            form.appendChild(csrfInput);

            // Append the form to the body and submit it
            document.body.appendChild(form);
            form.submit();
        }

        // Attach change event listeners to the category and size fields
        categoryField.addEventListener('change', function() {
            sizeField.value = ''; // Reset the size field
        });

        sizeField.addEventListener('change', submitCategoryAndSize);
    });
</script>