Is there a way to check for duplicate values in an array and display an alert if any duplicates are found? Here is the function that attempts to do this:
function checkDuplicateTenure(){
var f = document.frmPL0002;
var supplgrid = document.getElementById("mdrPymtGrid2");
var len = (supplgrid.rows.length) - 1;
for(var i=0;i<len;i++){
if (f.cbo_loanTenure[i+1].value == f.cbo_loanTenure[i].value) {
alert("DUPLICATE LOAN TENURE IN MONTH(S)");
}
}
return false;
}
This function successfully detects duplicate values in the array, but it encounters a JavaScript error when all values are different. The error message reads:
if (f.cbo_loanTenure[i+1].value == f.cbo_loanTenure[i].value) {
Unable to get property 'value' of undefined or null reference.
Thank you!