Ver Mensaje Individual
  #2 (permalink)  
Antiguo 07/01/2009, 22:10
Avatar de marcopoloaz06
marcopoloaz06
 
Fecha de Ingreso: julio-2007
Ubicación: México
Mensajes: 457
Antigüedad: 17 años, 6 meses
Puntos: 11
Respuesta: como utilizar onBlur con un for

Hola, siguiendo un poco tu ejemplo aver:
js:
Código javascript:
Ver original
  1. function calcularSuma(f) {
  2.     var ele = f.elements, valores = [], resultado = 4;
  3.     for(var i = ele.length;i--;)if( /^valor\d+$/.test( ele[i].name ) )valores.push( valores.length + 1 );
  4.     for(var i = valores.length;i--;)if(valores[i]%resultado != 0 && (valores[i] = f[ "valor"+ valores[i] ].value) == "")return false;
  5.     var suma = 0;
  6.     for(var i = 0;i < valores.length;i++){
  7.         if( (i + 1) % resultado == 0 ){
  8.             f[ "valor"+ (i + 1) ].value = isNaN(suma) ? "Error" : suma;
  9.             suma = 0;
  10.         }else{
  11.             suma += Number( valores[i] );
  12.         }
  13.     }
  14.     return false;
  15. }
html:
Código HTML:
<form name="formulario" onsubmit="return calcularSuma(this);">
    1<input type="text" name="valor1" /><br>
    2<input type="text" name="valor2" /><br>
    3<input type="text" name="valor3" /><br>
    resultado<input type="text" name="valor4" /><br>
    5<input type="text" name="valor5" /><br>
    6<input type="text" name="valor6" /><br>
    7<input type="text" name="valor7" /><br>
    resultado<input type="text" name="valor8" /><br>
    9<input type="text" name="valor9" /><br>
    10<input type="text" name="valor10" /><br>
    11<input type="text" name="valor11" /><br>
    resultado<input type="text" name="valor12" /><br>
    <input type="submit" value="resultado">
</form> 
Eso que se ve en el código de "& #37 ;" es %

Se puede optimizar más, pero eso salio así de rápido.

saludoss
:]
__________________
Aerolíneas Alicia :D