www.webdeveloper.com
Results 1 to 5 of 5

Thread: help with for loop

  1. #1
    Join Date
    Mar 2013
    Posts
    4

    help with for loop

    Hi guys,
    straight to the point.
    i have a function called count. I'm trying to loop through the array or what is it called. But I only getting the last number in the array. It isnt calculating.
    here is my code
    function count()
    {
    var getal =document.getElementsByName("subtots");
    var lengte = getal.length;
    var som=0;
    for(var i = 0; i <= lengte; i++ )
    {
    som=+ parseFloat(getal[i].value.replace(',','.')) || 0;
    }
    $('#tota').val(som);
    }
    please help?!

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,443
    Try...
    Code:
    som += parseFloat(getal[i].value.replace(',','.')) || 0;
    assuming "som" is a summation (sum)

  3. #3
    Join Date
    Mar 2013
    Posts
    4

    Thumbs up

    @JMRKER
    I have founded myself, just before your aswer came up.
    but thanks anyways

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,443

    Question

    Quote Originally Posted by siroj View Post
    @JMRKER
    I have founded myself, just before your aswer came up.
    but thanks anyways

    So, for the benefit of others viewing this thread who might have a similar problem,
    what was you final solution? What did you do to solve your original question?

  5. #5
    Join Date
    Mar 2013
    Posts
    4
    Code:
    var som = 0;
    var getal =document.getElementsByName("subtots");
    var subtotalen = Array.prototype.slice.call(getal);
    for(i=0;i<subtotalen.length;i++)
    	{
    	som+= parseFloat(subtotalen[i].value.replace(',','.')) || 0;
    	}
    $('#tota').val(som.toFixed(2));
    
    }
    Here it is, sorry I dont use forum often

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles