Tengo el siguiente código:
Código HTML:
<html> <head> <SCRIPT LANGUAGE=JavaScript> function Sumar() { var val1; var val2; var val3; var val1tot1 = 0; var val1tot2 = 0; var val1tot3 = 0; var val1tot; var val2tot; var val3tot; for (i=0; i<document.factura.lista1.length; i++){ val1 = (! parseFloat(document.factura.lista1[i].value))?0:parseFloat(document.factura.lista1[i].value); val1tot = val1 * document.factura.categoa.value; val1tot1 += val1tot; val2 = (! parseFloat(document.factura.lista2[i].value))?0:parseFloat(document.factura.lista2[i].value); val2tot = val2 * document.factura.categob.value; val1tot2 += val2tot; val3 = (! parseFloat(document.factura.lista3[i].value))?0:parseFloat(document.factura.lista3[i].value); val3tot = val3 * document.factura.categoc.value; val1tot3 += val3tot; document.factura.tot.value = val1tot1+val1tot2+val1tot3; } } </SCRIPT> </head> <body> <form name=factura> CATEGORIA A<br> <select name="lista1" onChange=Sumar()> <option selected value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <select name="lista1" onChange=Sumar()> <option selected value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <BR><BR>CATEGORIA B<br> <select name="lista2" onChange=Sumar()> <option selected value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <select name="lista2" onChange=Sumar()> <option selected value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <BR><BR>CATEGORIA C<br> <select name="lista3" onChange=Sumar()> <option selected value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <select name="lista3" onChange=Sumar()> <option selected value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <br><br>TOTAL<br> <input name=tot size=6><br><br> Catego A <input name=categoa size=6 type='text' value="20"><br> Catego B <input name=categob size=6 type='text' value="50"><br> Catego C <input name=categoc size=6 type='text' value="100"></td> </form> </body> </html>
Resumiento:
Va correctamente si...
Categoría A
Select
Select
Select
Categoría B
Select
Select
Categoría C
Select
Select
Select
Select
Falla si...
Va correctamente si...
Categoría A
Select
Select
Categoría B
Select
Categoría C
Select
Select
Muchas gracias!