Hi everyone Im new here and not very good with Javascript, so here im asking for a little help for my proyect
the problem is Im trying to calculate text fields from results of php query
my fields come from the query as amount1, amount2....
what i need is for JS to Sum those fields dynamically, I already did code for when i have all the values and for when the text field name is the same, but never for query results where the names are different
this is what i have so far but its not working
function calculatesumexcon() {
var a, total = 0;
var countJS = "<?=$count?>"; <-- variable of php that gives me the number of rows im getting on the query
var i ;
for ($i=0;$i<countJS;$i++){
var elements = document.getElementsById('amount' + i);
for(a=0; a<elements.length; a++){
total += (parseFloat(elements[a].value));
}
}
document.getElementById("totalextracon").value = total ;
}
Please help!