Strange result in comparison function

M

Marco Alting

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;
}
}

}
 
R

rf

Marco Alting said:
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

The string "1500" *is* greater than the string "10000".

Convert them to numbers.

Cheers
Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top