我想计算学生学历的百分比和分数。当获得或总分字段输入更改时,然后自动计算并显示百分比和等级
function PercCalculation() {
//console.log("PercCalculation() called");
var table = document.getElementById("gvEducationalQualifications");
if (table != null) {
var totalRows = table.rows.length;
for (var i = 1; i < totalRows; i++) {
var row = document.getElementById("gvEducationalQualifications").rows[i];
var marksObtained = parseInt(row.cells[8].innerText);
var maxMarks = parseInt(row.cells[9].innerText);
var marksInput = row.cells[8].getElementsByClassName("mrksobteq")[0]; // assuming marks input is the first input element in the cell
var maxMarksInput = row.cells[9].getElementsByClassName("totalmarkseq")[0]; // assuming max marks input is the second input element in the cell
// attach the oninput event to the marks input field
marksInput.oninput = function () {
console.log("PercCalculation() called");
alert("Hello! I am an alert box!!");
marksObtained = parseInt(this.value);
calculatePercentageAndGrade(row, marksObtained, maxMarks);
};
// attach the oninput event to the max marks input field
maxMarksInput.oninput = function () {
maxMarks = parseInt(this.value);
calculatePercentageAndGrade(row, marksObtained, maxMarks);
};
// calculate the initial percentage and grade
calculatePercentageAndGrade(row, marksObtained, maxMarks);
}
}
}
function calculatePercentageAndGrade(row, marksObtained, maxMarks) {
var percentage = (marksObtained / maxMarks) * 100;
row.cells[10].innerText = percentage.toFixed(2) + "%";
var division;
if (percentage >= 60) {
division = "1st";
}
else if (percentage >= 45 && percentage < 60) {
division = "2nd";
}
else if (percentage >= 30 && percentage < 45) {
division = "3rd";
}
else {
division = "Fail";
}
row.cells[11].innerText = division;
}