Tengo un codigo que suma los textbox muy bien pero cuando le pongo en un textbox el valor 0 (cero) no me lo toma en cuenta me dice que faltan valores estoy usando parseFloat les dejo mi codigo y espero que si puedan ayudarme
gracias de antemano y saludos.
Código HTML:
<script> function validarNumA8(){ float = validarfloat(document.miForm.valor1.value); if (float==""){ //document.miForm.num1.value="" return "" }else{ res1=true return float } } function validarNumB8(){ float = validarfloat(document.miForm.valor2.value); if (float==""){ //document.miForm.num2.value = "" return "" }else{ res2=true return float } } function validarNumC8(){ float = validarfloat(document.miForm.valor3.value); if (float==""){ //document.miForm.num2.value = "" return "" }else{ res3=true return float } } function validarNumD8(){ float = validarfloat(document.miForm.valor4.value); if (float==""){ //document.miForm.num1.value="" return "" }else{ res4=true return float } } function validarNumE8(){ float = validarfloat(document.miForm.valor5.value); if (float==""){ //document.miForm.num2.value = "" return "" }else{ res5=true return float } } function validarNumF8(){ float = validarfloat(document.miForm.valor6.value); if (float==""){ //document.miForm.num2.value = "" return "" }else{ res6=true return float } } function validarfloat(valor){ valor = parseFloat(valor) if (isNaN(valor)) { return "" }else{ return valor } } function sumarc8(){ if (validarNumA8()=="" || validarNumB8()=="" || validarNumC8()=="" || validarNumD8()=="" || validarNumE8()=="" || validarNumF8()==""){ alert ("Faltan Datos") document.miForm.totalc8.value = "" }else{ sol = validarNumA8()+validarNumB8()+validarNumC8()+validarNumD8()+validarNumE8()+validarNumF8() document.miForm.totalc8.value = sol } } </script> <style type="text/css"> <!-- .tb2 { background-color : #FEFE9A; border: 1px solid #666666; width: 148px; } .Estilo5 {font-family: Calibri; color: #666666; } .total { background-color : #FFFFFF; border: 1px solid #666666; width: 148px; } --> </style> <form name="miForm" method="post" action=""> <table width="200" border="0"> <tr> <td width="40">1</td> <td width="150"><input name="valor1" type="text" class="tb2" id="valor1" onblur="validarNumA8()" /></td> </tr> <tr> <td>2</td> <td><input name="valor2" type="text" class="tb2" id="valor2" onblur="validarNumB8()" /></td> </tr> <tr> <td>3</td> <td><input name="valor3" type="text" class="tb2" id="valor3" onblur="validarNumC8()" /></td> </tr> <tr> <td>4</td> <td><input name="valor4" type="text" class="tb2" id="valor4" onblur="validarNumD8()" /></td> </tr> <tr> <td>5</td> <td><input name="valor5" type="text" class="tb2" id="valor5" onblur="validarNumE8()" /></td> </tr> <tr> <td>6</td> <td><input name="valor6" type="text" class="tb2" id="valor6" onblur="validarNumF8()" /></td> </tr> <tr> <td> </td> <td><span class="Estilo5"> <input name="totalc8" class="total" onfocus = "sumarc8()" id="totalc8" /> </span></td> </tr> </table> </form>