locked
How to get the sum of array elements RRS feed

  • Question

  • Hi all,

     

    i was trying to get the sum of array values retrieved by a xml query, so i have used the following code:

     

    var doc = new ActiveXObject("MSXML2.DOMDocument");

    doc.async = false;

    doc.loadXML(resultXml);

    var m = doc.selectNodes("//q1:manualdiscountamount");

    var totalLineItemDiscountAmount=0;

    if(m!=null)

    {

        for(i=0;i<m.length;i++)

        {

            alert("manualdiscountamount"+m[i].text);

            totalLineItemDiscountAmount+=m[i].text;

        }

    }

    alert("the sum is:"+totalLineItemDiscountAmount);

     

    but for some reason that i cannot understand, this code concatenate the elements !!!

     

    could anybody please help me to modify THIS code so i can get the summation of array values

     

    any help will be appreciated

     

    thanks in advance

    Monday, November 15, 2010 10:50 PM

Answers

All replies