Ver Mensaje Individual
  #3 (permalink)  
Antiguo 04/10/2013, 02:00
Avatar de javioreto
javioreto
 
Fecha de Ingreso: enero-2005
Ubicación: C:\España\Bilbao
Mensajes: 1.212
Antigüedad: 19 años, 3 meses
Puntos: 15
Respuesta: Suma de todos los textbox excepto de uno

Código HTML:
<script type="text/javascript">
   function sumar(c) { //alert(c);
      var campo = document.getElementById('form1');
      var subtotal = 0;
 
      if (!/^d*$/.test(c)) // <-- problema, busca solución
         //return;
      
      for (var i = 0; i < campo.length - 1; i++) { 
         if (!/^d+$/.test(campo[i].value)) // <-- problema, busca solución
           // continue;


if(i!=6){
         subtotal += parseFloat(campo[i].value);
}


      }
		var resultado =Math.round(subtotal*100)/100
       document.form1.res.value = resultado;
	   
   }
</script>
 
<form id="form1" name="form1" action="" method="post">

1:<input type="text" name="sum[]" value="0" onBlur="sumar(this.value);" /><br />
2:<input type="text" name="sum[]" value="0" onBlur="sumar(this.value);" /><br />
3:<input type="text" name="sum[]" value="0" onBlur="sumar(this.value);" /><br />
4:<input type="text" name="sum[]" value="0" onBlur="sumar(this.value);" /><br />
5:<input type="text" name="sum[]" value="0" onBlur="sumar(this.value);" /><br />
6:<input type="text" name="nosumar" value="0" /><br />
   Resultado:
   <input type="text" id="res" name="res" value="0" />
</form>