Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/03/2010, 16:08
Avatar de America|UNK
America|UNK
 
Fecha de Ingreso: noviembre-2006
Ubicación: Piura - Perú
Mensajes: 582
Antigüedad: 18 años, 2 meses
Puntos: 56
Respuesta: Validar un par de campos...

Código HTML:
Ver original
  1. <form name="manageform">
  2. <select name="mainvals">
  3. <option value="01">Saldos</option>
  4. <option value="22">Cuentas</option>
  5. <option value="25">Salarios</option>
  6. <input type="text" name="numbox" value="01" />
  7. <input type="submit" />
  8. </form>
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. var initManage = function(){
  3.     var f = document.manageform, n = f.numbox, m = f.mainvals;
  4.     m.onchange = function(){
  5.         var e = this, v = e.options[e.selectedIndex].value;
  6.         if(v != n.value.substr(0,2)){
  7.             n.value = v;
  8.         }
  9.         n.style.color = '';
  10.     }
  11.     n.onkeyup = function(e){
  12.         var e = this, V = e.value, k = m.options[m.selectedIndex].value;
  13.             e.style.color = V.substr(0,2) != k ? 'red' : '';
  14.     }
  15.     f.onsubmit = function(){
  16.         return (m.options[m.selectedIndex].value == n.value.substr(0,2));
  17.     }
  18. }
  19. initManage() // correr funciones
  20. </script>
__________________
/* El que atiende, entiende..., el que entiende, aprende!.
Desarrollo Web Freelance, Contactar */

Última edición por America|UNK; 23/03/2010 a las 16:13