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 originalfunction objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
//Función para recoger los datos del formulario y enviarlos por post
function OnSubmitBooking()
{
if(document.Booking.emailtrue.value != document.Booking.repeat_email.value)
{
divresult = document.getElementById('repeat_emailbox');
divresult.className = 'validation'
divresult.innerHTML = 'Email and repeat email are not equal';
document.Booking.repeat_email.focus();
return false;
}
var info = {
names : ['namebox' , 'Please fill in name' ],
passport : ['passportbox' , 'Please fill in your identification' ],
emailtrue : ['emailtruebox' , 'Please fill in email' ],
repeat_email: ['repeat_emailbox', 'Please repeat email' ],
telmobile : ['telmobilebox' , 'Please fill in mobile to bring on holiday' ],
test : ['resultbooking' , 'Please answer the security question' ]
}
for( key in info ) {
if(document.Booking[key].value == '')
{
divresult = document.getElementById(info[key][0])
divresult.className = 'validation'
divresult.innerHTML = info[key][1];
document.Booking[key].focus();
return false;
}
}
divresult = document.getElementById('resultbooking');
//recogemos los valores de los inputs
enviar = document.solicitud.enviar.value;
question = document.solicitud.question.value;
answer = document.solicitud.answer.value;
test = document.solicitud.test.value;
var ajaxcaptcha = objetoAjax();
ajaxcaptcha.open("POST", "/pasarela/captchaajax.php", true);
ajaxcaptcha.onreadystatechange = function () {
if (ajaxcaptcha.readyState == 4) {
if (ajaxcaptcha.responseText === "ok") {
return true;
} else {
divresult.innerHTML = "The answer to the security question was not correct"
<!-- LimpiarCampos();-->
}
}
}
ajaxcaptcha.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxcaptcha.send("test=" + test + "&enviar=" + enviar + "&answer=" + answer +
"&question=" + question + "");
return false;
}