Ver Mensaje Individual
  #5 (permalink)  
Antiguo 05/06/2015, 15:39
dardo123
 
Fecha de Ingreso: agosto-2014
Mensajes: 12
Antigüedad: 9 años, 9 meses
Puntos: 0
Respuesta: Comparar el contenido de 2 celdas de una tabla

Hola!

No logro hacerlo funcionar, dejé el código así:

Código PHP:
echo "<tr><td class='user-mobile'><input type='text' style='text-align: center' name='km_prog[]' class='foo' onkeypress='cambio(this, '.bar')' value='".$km_prog."'></td>
<td class='user-mobile'><input type='text' style='text-align: center' name='km_reales[]' class='bar' onkeypress='cambio(this, '.foo')' value='"
.$km_reales."'></td></tr> \n"
Código:
<script type="text/javascript">
    	    function cambio(input, clase){
        var fila = input.parentNode.parentNode,
            otroInput = fila.querySelector(clase);
     
        if (input.value != otroInput.value){
            input.style.backgroundColor = "red";
        }
        else{
            input.style.backgroundColor = "white";
        }
    }
    </script>