Hi,
I have this function that checks formfields with an onChange. But it seems
to get my comparisons wrong. I've listed the function below, and give some
sample values here, the committed value is changed from 1000 to 1500 and
then gets a popup that it is greater than the Budget??? I hope someone can
help:
Budget = 10000
committed = 1500
actual = 0
accrual = 0
function ValueChanged(obj, variation){
var ChangedValue = document.getElementById(obj);
var Budget = document.getElementById("Budget" + variation);
var Committed =document.getElementById("committed" + variation);
var Actual = document.getElementById("actual" + variation);
var Accrual = document.getElementById("accrual" + variation);
var ChangedHidden = document.getElementById("changedValues" + variation);
ChangedValue.style.backgroundColor='#ffcc00';
ChangedHidden.value = true;
alert(obj + " " + Budget.value + " " + Committed.value + " " +
Actual.value + " " + Accrual.value);
//check values entered in field
//Check Committed value
if(obj == "committed" + variation){
if(Budget.value < Committed.value){
alert("Committed value can not be greater than the Budget");
Committed.focus();
Committed.select();
return false;
}
if(Committed.value < (Actual.value + Accrual.value)){
alert("Committed value can not be less than Actual + Accrual");
Committed.focus();
Committed.select();
return false;
}
}
//Check Actual value
if(obj == "actual" + variation){
alert("actual is true");
if(Actual.value > Budget.value){
alert("Actual value can not be greater than the Budget");
Actual.focus();
Actual.select();
return false;
}
if((Actual.value + Accrual.value) > Budget.value){
alert("Actual + Accrual can not be greater than the Budget");
Actual.focus();
Actual.select();
return false;
}
}
//Check Accrual
if(obj == "accrual" + variation){
alert("accrual is true");
if(Accrual.value > Budget.value){
alert("Accrual value can not be greater than the Budget");
Accrual.focus();
Accrual.select();
return false;
}
if((Actual.value + Accrual.value) > Budget.value){
alert("Actual + Accrual can not be greater than the Budget");
Accrual.focus();
Accrual.select();
return false;
}
}
}