I am am trying to prevent a user from going from a specific number value parameter from say 1 to 9999.99. I have multiple input values that I have assigned ids. I am using a switch statement to set the parameters (min & max) of these, so first would be from 1 to 9999.99, the second be 1 to 999.99, the third 1 to 99.99. However, I can still enter over these values and don't get dinged on my restrictions could some one please provide insight, still trying to work this through. Thanks for any help
function getMinMax(ctrlId) {
let min = 0;
let max = 9999;
switch (ctrlId) {
case "aID":
min = 1;
max = 99999.99;
break;
case "bID":
min = 1;
max = 999.99;
break;
case "cID":
min = 1;
max = 99.99;
break;
}
return { min: min, max: max };
}
async function checkMinMax(ctrl) {
let value = await ctrl.value();
if(value === '') return;
let ctrlId = await ctrl.id;
let minMax = getMinMaxForField(ctrlId);
let isNotANumber = Number.isNaN(value);
if(!isNotANumber && Number.parseFloat(value) >= minMax.min && Number.parseFloat(value) <= minMax.max) {
ctrl.value(value);
} else {
alert('Please enter a value between ' + minMax.min + ' and ' + minMax.max + '.')
ctrl.value('');
}
}