Ver Mensaje Individual
  #13 (permalink)  
Antiguo 10/03/2014, 07:18
helenp
 
Fecha de Ingreso: mayo-2009
Mensajes: 382
Antigüedad: 15 años
Puntos: 6
Respuesta: Opinion validación javascript

Cita:
Iniciado por Pantaláimon Ver Mensaje
Supongo que lo que estas buscando que se produzca un cambio cuando quites el foco. En este caso existe el evento onblur:
http://jsfiddle.net/jefebrondem/q7tqU/
Gracias,
Aunque no sé si me convence el onblur, me gusta el onsubmit, lo estudiaré,
tenía en mente algo como onchange, o si valida innerhtml = display.none o ''.

Estoy metiendo la validación del captcha con javascript y no se como devovler true.
He intentado esto y tambien de dar el mensaje de error en el archivo php y solo devuelve false.
Esto es el ajax:
Código Javascript:
Ver original
  1. function objetoAjax(){
  2.     var xmlhttp=false;
  3.     try {
  4.         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  5.     } catch (e) {
  6.  
  7.     try {
  8.         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  9.     } catch (E) {
  10.         xmlhttp = false;
  11.     }
  12. }
  13.  
  14. if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  15.       xmlhttp = new XMLHttpRequest();
  16.     }
  17.     return xmlhttp;
  18. }
  19.  
  20. //Función para recoger los datos del formulario y enviarlos por post  
  21. function OnSubmitBooking()
  22. {
  23.     if(document.Booking.emailtrue.value != document.Booking.repeat_email.value)
  24.  {
  25. divresult = document.getElementById('repeat_emailbox');
  26. divresult.className = 'validation'
  27. divresult.innerHTML = 'Email and repeat email are not equal';
  28.  document.Booking.repeat_email.focus();
  29.         return false;
  30.  }
  31.         var info = {
  32.             names        : ['namebox'        , 'Please fill in name' ],
  33.             passport    : ['passportbox'    , 'Please fill in your identification' ],
  34.             emailtrue   : ['emailtruebox'   , 'Please fill in email' ],
  35.             repeat_email: ['repeat_emailbox', 'Please repeat email' ],
  36.             telmobile   : ['telmobilebox'   , 'Please fill in mobile to bring on holiday' ],
  37.             test        : ['resultbooking'  , 'Please answer the security question' ]
  38.         }
  39.         for( key in info ) {
  40.             if(document.Booking[key].value == '')
  41.             {
  42.                 divresult = document.getElementById(info[key][0])
  43.                 divresult.className = 'validation'
  44.                 divresult.innerHTML = info[key][1];
  45.                 document.Booking[key].focus();
  46.                 return false;
  47.             }
  48.         }
  49.         divresult = document.getElementById('resultbooking');
  50.   //recogemos los valores de los inputs
  51.  
  52. enviar = document.solicitud.enviar.value;
  53.   question = document.solicitud.question.value;
  54.   answer = document.solicitud.answer.value;
  55.   test = document.solicitud.test.value;
  56.   var ajaxcaptcha = objetoAjax();
  57.   ajaxcaptcha.open("POST", "/pasarela/captchaajax.php", true);
  58.   ajaxcaptcha.onreadystatechange = function () {   
  59.  if (ajaxcaptcha.readyState == 4) {
  60.       if (ajaxcaptcha.responseText === "ok") {
  61. return true;
  62.       } else {
  63.         divresult.innerHTML = "The answer to the security question was not correct"
  64.       <!--  LimpiarCampos();-->
  65.       }
  66.     }
  67. }
  68.  
  69.   ajaxcaptcha.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  70.   ajaxcaptcha.send("test=" + test + "&enviar=" + enviar + "&answer=" + answer +
  71.        "&question=" + question + "");
  72.         return false;
  73. }