help with simple for loop

Discussion in 'C#' started by eyoung, Jan 13, 2011.

  1. #1
    The script sums 7 fields. To test I put an alert in it. When ran, I get 7 alert messages (normal). If I move the alert message down one bracket '}', out of the for loop, I get no alerts (not good). What's wrong with my logic?


    function mistot(){
    var ep = document.forms[0].elements;
    var myamt = 'm-amt';
    var mytot = 0;

    for(var i = 1; i <= 8; ++i) {
    if(isFloat(ep[myamt + i].value)){
    mytot += +ep[myamt + i].value;
    }
    alert('test')
    }
    }
     
    eyoung, Jan 13, 2011 IP
  2. miguelf

    miguelf Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    48
    #2
    This is a JavaScript issue not ASP. But the problem I would guess is with: mytot += +ep[myamt + i].value; You have a '+' before ep. It may also be that the index 'myamt + i' is out of range or that the object does not support 'value'.
     
    miguelf, Jan 13, 2011 IP
  3. wayons

    wayons Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The line "mytot += +ep[myamt + i].value; " should be 'mytot += ep[myamt + i].value; ". There is an extra '+' symbol
     
    wayons, Jan 17, 2011 IP