Ver Mensaje Individual
  #2 (permalink)  
Antiguo 17/08/2009, 09:46
Avatar de goyo_
goyo_
 
Fecha de Ingreso: agosto-2009
Mensajes: 91
Antigüedad: 17 años, 1 mes
Puntos: 1
Respuesta: Suma de valores de un formulario sin boton

Ponte a jugar con el siguiente codigo:

Código PHP:
<input id="hijos">
<
input id="hijosMujeres">
<
input id="hijosHombres">

<
script>
function 
id(x) {
    return 
document.getElementById(x);
}

function 
toInt(x) {
    return 
parseInt(id(x).value, 10);
}

function 
calcularNumeroHijos() {
    var 
a = toInt('hijos'),
        
b = toInt('hijosMujeres'),
        
c = toInt('hijosHombres');
    
    
a = isNaN(a) ? 0 : a;
    
b = isNaN(b) ? 0 : b;
    
c = isNaN(c) ? 0 : c;
    
    
id('hijosHombres').value = a - b;
}

id('hijos').onkeyup = calcularNumeroHijos;
id('hijosMujeres').onkeyup = calcularNumeroHijos;
id('hijosHombres').onkeyup = calcularNumeroHijos;
</script>