# help with for loop

• 03-28-2013, 05:40 AM
siroj
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);
}
• 03-28-2013, 09:10 AM
JMRKER
Try...
Code:

`som += parseFloat(getal[i].value.replace(',','.')) || 0;`
assuming "som" is a summation (sum)
• 04-02-2013, 01:54 AM
siroj
@JMRKER
I have founded myself, just before your aswer came up.
but thanks anyways;)
• 04-02-2013, 12:56 PM
JMRKER
Quote:

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

:confused:
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?
• 04-03-2013, 09:22 AM
siroj
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

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.25377 seconds
• Memory Usage 2,351KB
• Queries Executed 11 (?)
Template Usage (21):
• (2)bbcode_code_printable
• (1)bbcode_quote_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (41):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• bbcode_fetch_tags
• bbcode_create
• bbcode_parse_start
• bbcode_parse_complete_precache
• bbcode_parse_complete
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates