Strange result in comparison function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marco Alting

    Strange result in comparison function

    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(ob j, variation){
    var ChangedValue = document.getEle mentById(obj);
    var Budget = document.getEle mentById("Budge t" + variation);
    var Committed =document.getEl ementById("comm itted" + variation);
    var Actual = document.getEle mentById("actua l" + variation);
    var Accrual = document.getEle mentById("accru al" + variation);
    var ChangedHidden = document.getEle mentById("chang edValues" + variation);
    ChangedValue.st yle.backgroundC olor='#ffcc00';
    ChangedHidden.v alue = 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("Committe d value can not be greater than the Budget");
    Committed.focus ();
    Committed.selec t();
    return false;
    }
    if(Committed.va lue < (Actual.value + Accrual.value)) {
    alert("Committe d value can not be less than Actual + Accrual");
    Committed.focus ();
    Committed.selec t();
    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.valu e + 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.valu e > Budget.value){
    alert("Accrual value can not be greater than the Budget");
    Accrual.focus() ;
    Accrual.select( );
    return false;
    }
    if((Actual.valu e + Accrual.value) > Budget.value){
    alert("Actual + Accrual can not be greater than the Budget");
    Accrual.focus() ;
    Accrual.select( );
    return false;
    }
    }

    }


  • rf

    #2
    Re: Strange result in comparison function


    "Marco Alting" <marco@hotmail. com> wrote in message
    news:glAab.1402 98$P03.26275494 @amsnews02.chel lo.com...[color=blue]
    > 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[/color]

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

    Convert them to numbers.

    Cheers
    Richard.


    Comment

    Working...