Hello friends.
I got a problem. I have a form where I display quantity, value, and total. These fields are generated dynamically in php and when you put a value in the field value, automatically the field total is calculated depending of the quantity.
Here is the code.
[CODE]
function calcularTotalParcial(index){
var elementos = document.getElementsByName(“total”);
var cantidad = document.getElementsByName(“cantidad”)[index];
var valor = document.getElementsByName(“valor”)[index];
var total = document.getElementsByName(“total”)[index];
for(var i=0; i<elementos.length; i++){
if((cantidad.value != “”) && (valor.value != “”) && (elementos.value != “”)){
total.value = cantidad.value*valor.value;
calcularTotal();
}
else{
if(total.value != “”){
total.value = “”;
calcularTotal();
}
}
}
}
function calcularTotal(){
var totales = document.getElementsByName(“total”);
var suma = 0;
for(var i=0; i<totales.length; i++){
if(totales[i].value != “”){
suma += totales[i].value*1;
}
}
document.getElementById(“total_venta”).value = suma;
}
and the form is like this.
[CODE]
<input name=”cantidad” type=”text” value=”<? echo $row1[‘a198Cantidad’];?>” size=”3″ onKeyUp=”calcularTotalParcial(1)”></td>
<td><input type=”text” name=”valor” onKeyUp=”calcularTotalParcial(1)”></td>
<td colspan=”2″><input name=”total” type=”text” readonly=”true”></td>
As you can see I’m passing the position 1 to the function and it works fine. But it only calculates the position 1. I need that when I put a value in eachone of the input name=value it calcualtes for eachone not for only one position. I think that the question is how can I pass the n input texts to the function.
Thanks!!!