Welcome to WebmasterWorld Guest from 34.237.76.91

Forum Moderators: open

Message Too Old, No Replies

javascript + ajax validation does not work 100% in chrome

     
9:39 am on Mar 19, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Nov 27, 2003
posts: 1318
votes: 0


Hi,
Below script works in internet explorer and in firefox.
I have 6 fields validated with javascript and the 1 with Ajax.
In Chrome if I leave the fields blank and submit, then fill in the fields one by one, the javascript validation is not ejecuted or I think the form is not submitted.
The php file is being opened.

However If I fill in the javascript fields correctly then submit the javascript validation works perfect.
function 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;
}
function OnSubmitBooking()
{
if(document.Booking.emailtrue.value != document.Booking.repeat_email.value)
{
document.getElementById('repeat_emailbox').style.display = "block";
divresult = document.getElementById('repeat_emailbox');
divresult.className = 'validation'
divresult.innerHTML = 'Emails 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' ]
}
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');

var enviar = document.Booking.enviar.value,
question = document.Booking.question.value,
answer = document.Booking.answer.value,
test = document.Booking.test.value;
var ajaxcaptcha = objetoAjax();
ajaxcaptcha.open("POST", "captchaajax.php", true);
ajaxcaptcha.onreadystatechange = function () {
if (ajaxcaptcha.readyState==1 || ajaxcaptcha.readyState==2 || ajaxcaptcha.readyState==3)
{
divresult.className = 'validationok'
divresult.innerHTML = 'Please wait...';
}
if (ajaxcaptcha.readyState == 4) {
if (ajaxcaptcha.responseText === "Loading, please wait") {
var enviar = document.createElement('input');
enviar.type = 'hidden';
enviar.name = 'enviar';
enviar.value = true;
document.Booking.appendChild(enviar);
document.Booking.submit();
} else {
divresult.className = 'validation'
divresult.innerHTML = ajaxcaptcha.responseText
}
}
}

ajaxcaptcha.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxcaptcha.send("test=" + test + "&enviar=" + enviar + "&answer=" + answer +
"&question=" + question + "");
return false;
}
6:37 pm on Mar 19, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 5021
votes: 26


I'd start by opening Chrome's dev tools (press F12), view the Sources tab, and enter a breakpoint at the top of your function, then when that code executes, step through it to see what it's doing.
8:31 pm on Mar 19, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Nov 27, 2003
posts: 1318
votes: 0


I'd start by opening Chrome's dev tools (press F12), view the Sources tab, and enter a breakpoint at the top of your function, then when that code executes, step through it to see what it's doing.

Not sure I did it right but when I clicked f8 after I selected the breakpoint, another .js script for a sharebutton came up. I deleted this and now it works.
Thanks
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members