<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Board Result</title>
    <style>
       
        .form-container-bresults {
            width: 100%;
            max-width: 1200px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
            background-color: #f9f9f9;
        }
        formbresults {
            display: flex;
            flex-direction: column;
        }
        .form-group-bresults {
            display: flex;
            flex-direction: column;
            margin-bottom: 15px;
        }
        .form-group-bresults label {
            margin-bottom: 5px;
        }
        .form-group-bresults input,
        .form-group-bresults select {
            width: 90%;
            padding: 8px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .class-group-bresults {
            display: grid;
            grid-template-columns: repeat(9, 1fr);
            gap: 5px;
            margin-bottom: 15px;
        }
        .class-group-bresults .form-group-bresults {
            margin: 0;
            display: flex;
            flex-direction: column;
        }
        .class-group-bresults label {
            margin-bottom: 5px;
            text-align: left;
        }
        .class-group-bresults input,
        .class-group-bresults select {
            width: 90%;
            padding: 4px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .form-group-bresults button {
            margin-top: 10px;
            padding: 10px 20px;
            color: #fff;
            border: none;
            cursor: pointer;
        }
        .add-more-bresults {
            background-color: #007bff;
            width: 30%;
            padding: 10px;
            border-radius: 4px;
        }
        .removebresults {
            background-color: #dc3545;
            width: 80%;
			margin-top:23px;
			height:50%;
            padding: 5px;
            border-radius: 4px;
        }
        .button-container-bresults {
            text-align: center;
        }
        .button-container-bresults button {
            margin: 5px;
        }
    </style>
</head>
<body>

<div align="center">
    <div class="form-container-bresults">
            <div class="form-group-bresults">
                <label for="emisCode">EMIS Code:</label>
                <input type="text" id="emisCode" name="emis_code[]" >
            </div>
            <div id="fieldsContainerbresults">
                <div class="class-group-bresults">
                    <div class="form-group-bresults">
                        <label for="className">Class Name</label>
                        <select id="className" name="class_name[]" required>
                            <option value="">Select Class...</option>
                            <option value="5">5th</option>
                            <option value="8">8th</option>
                            <option value="9">9th</option>
                            <option value="10">10th</option>
                            <option value="11">First Year</option>
                            <option value="12">Second Year</option>
                        </select>
                    </div>
                    <div class="form-group-bresults">
                        <label for="resultyear">Year</label>
                        <input type="number" id="resultyear" name="resultyear[]" min="2020" required>
                    </div>
                    <div class="form-group-bresults">
                        <label for="Arts">Arts</label>
                        <input type="number" id="Arts" name="Arts[]" oninput="calculateTotalAndPercentage(this)" min="0">
                    </div>
                    <div class="form-group-bresults">
                        <label for="Science">Science</label>
                        <input type="number" id="Science" name="Science[]" oninput="calculateTotalAndPercentage(this)" min="0">
                    </div>
                    <div class="form-group-bresults">
                        <label for="Totalstudents">Total Students</label>
                        <input type="number" id="Totalstudents" name="Total_students[]" readonly>
                    </div>
                    <div class="form-group-bresults">
                        <label for="Pass">Pass</label>
                        <input type="number" id="Pass" name="Pass[]" oninput="calculatePercentage(this)" min="0" >
                    </div>
                    <div class="form-group-bresults">
                        <label for="Fail">Fail</label>
                        <input type="number" id="Fail" name="Fail[]" min="0">
                    </div>
                    <div class="form-group-bresults">
                        <label for="result_percent">Percentage</label>
                        <input type="number" id="result_percent" name="result_percent[]" readonly>
                    </div>
                    <button type="button" class="removebresults" onclick="removeFieldsbresults(this)">Remove</button>
                </div>
            </div>
            <div class="button-container-bresults">
                <button type="button" class="add-more-bresults" onclick="addFieldsbresults()">Add More</button>
            </div>
    </div>

    <script>
        function addFieldsbresults() {
            const containerbresults = document.getElementById('fieldsContainerbresults');
            const classGroup = document.createElement('div');
            classGroup.className = 'class-group-bresults';

            classGroup.innerHTML = `
                <div class="form-group-bresults">
                    <label for="className">Class Name</label>
                    <select id="className" name="class_name[]" required>
                        <option value="">Select Class...</option>
                        <option value="5">5th</option>
                        <option value="8">8th</option>
                        <option value="9">9th</option>
                        <option value="10">10th</option>
                        <option value="11">First Year</option>
                        <option value="12">Second Year</option>
                    </select>
                </div>
                <div class="form-group-bresults">
                    <label for="resultyear">Year</label>
                    <input type="number" id="resultyear" name="resultyear[]" min="2020" required>
                </div>
                <div class="form-group-bresults">
                    <label for="Arts">Arts</label>
                    <input type="number" id="Arts" name="Arts[]" oninput="calculateTotalAndPercentage(this)" min="0">
                </div>
                <div class="form-group-bresults">
                    <label for="Science">Science</label>
                    <input type="number" id="Science" name="Science[]" oninput="calculateTotalAndPercentage(this)" min="0">
                </div>
                <div class="form-group-bresults">
                    <label for="Totalstudents">Total Students</label>
                    <input type="number" id="Totalstudents" name="Total_students[]" readonly >
                </div>
                <div class="form-group-bresults">
                    <label for="Pass">Pass</label>
                    <input type="number" id="Pass" name="Pass[]" oninput="calculatePercentage(this)" min="0" >
                </div>
                <div class="form-group-bresults">
                    <label for="Fail">Fail</label>
                    <input type="number" id="Fail" name="Fail[]" min="0">
                </div>
                <div class="form-group-bresults">
                    <label for="result_percent">Percentage</label>
                    <input type="number" id="result_percent" name="result_percent[]" readonly>
                </div>
                <button type="button" class="removebresults" onclick="removeFieldsbresults(this)">Remove</button>
            `;

            containerbresults.appendChild(classGroup);
        }

        function removeFieldsbresults(button) {
            const classGroup = button.parentNode;
            classGroup.parentNode.removeChild(classGroup);
        }

        function calculateTotalAndPercentage(element) {
            const classGroup = element.closest('.class-group-bresults');
            const arts = classGroup.querySelector('input[name="Arts[]"]').value;
            const science = classGroup.querySelector('input[name="Science[]"]').value;
            const totalStudents = classGroup.querySelector('input[name="Total_students[]"]');

            const total = (parseInt(arts) || 0) + (parseInt(science) || 0);
            totalStudents.value = total;

            calculatePercentage(classGroup.querySelector('input[name="Pass[]"]'));
        }

        function calculatePercentage(element) {
            const classGroup = element.closest('.class-group-bresults');
            const pass = classGroup.querySelector('input[name="Pass[]"]').value;
            const totalStudents = classGroup.querySelector('input[name="Total_students[]"]').value;
            const percentage = classGroup.querySelector('input[name="result_percent[]"]');

            if (totalStudents > 0) {
                percentage.value = ((parseInt(pass) || 0) / totalStudents * 100).toFixed(2);
            } else {
                percentage.value = 0;
            }
        }
    </script></div>
</body>
</html>
