napsternapster Posted July 30, 2009 Share Posted July 30, 2009 Hi ppl. I'm validating two records entity type and name using ajax but my problem now is that it works well all other browsers except firefox. var basiccounter ; function ServerSideValidation(contact_counter,detailed_counter,f,selection,o_name) { basiccounter = 0; //sending entity type to the server var urlEntity = "entity_type.php"; urlEntity = urlEntity+"?type="+document.getElementBYId(selection).value; urlEntity = urlEntity+"&sid="+Math.random(); checkName(urlEntity,"GET", "sel_id", "lblEntity_error"); //sending official name to the server var urlName="checkname.php"; urlName= urlName+"?q="+document.getElementBYId(o_name).value; urlName = urlName+"&sid="+Math.random(); checkName(urlName,"GET", "txtOff_name", "lblOff_error"); CheckErrors(f,basiccounter); } function checkName(url, method, id, label,f,detailed_counter) { var xmlhttp = new GetXmlHttp(); if(method == "GET") { xmlhttp.open(method, url, false); xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { if(xmlhttp .responseText != 0) { basiccounter++; document.getElementById(label).innerHTML = xmlhttp.responseText; document.getElementById(id).style.background = "pink"; } else { document.getElementById(label).innerHTML = ""; document.getElementById(id).style.background = "white"; } } } xmlhttp.send(null); } } function CheckErrors(f,error) { if(error > 0 ) { alert("found some errors on the serverside validation"); } else { f.submit(); } } The code needs to function the same way in chrome,IE,opera,firefox and netscape Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted July 30, 2009 Share Posted July 30, 2009 Don't mean to be rude but It will increase the readability of your code on this forum. What is the error you receive in FF? Quote Link to comment Share on other sites More sharing options...
trq Posted July 30, 2009 Share Posted July 30, 2009 You might want to at least give us some details about what its not doing. Just saying it doesn't work doesn't help much. Can we see GetXmlHttp() ? Quote Link to comment Share on other sites More sharing options...
napsternapster Posted July 30, 2009 Author Share Posted July 30, 2009 Here is the GetXmlHttp function bellow function GetXmlHttp() { // will store the reference to the XMLHttpRequest object var xmlHttp; // this should work for all browsers except IE6 and older try { // try to create XMLHttpRequest object xmlHttp = new XMLHttpRequest(); } catch(e) { // assume IE6 or older var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'); // try every prog id until one works for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) { try { // try to create XMLHttpRequest object xmlHttp = new ActiveXObject(XmlHttpVersions); } catch (e) {} } } // return the created object or display an error message if (!xmlHttp) { alert("Error creating the XMLHttpRequest object."); } else { return xmlHttp; } } Quote Link to comment Share on other sites More sharing options...
napsternapster Posted July 30, 2009 Author Share Posted July 30, 2009 It suppose to show an error message if the information required is not entered and the user hits the submit button but at this point it submits the form without any validation using ajax Quote Link to comment Share on other sites More sharing options...
napsternapster Posted July 30, 2009 Author Share Posted July 30, 2009 Hi ppl. I'm validating two records entity type and name using ajax but my problem now is that it works well all other browsers except firefox. function GetXmlHttp() { // will store the reference to the XMLHttpRequest object var xmlHttp; // this should work for all browsers except IE6 and older try { // try to create XMLHttpRequest object xmlHttp = new XMLHttpRequest(); } catch(e) { // assume IE6 or older var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'); // try every prog id until one works for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) { try { // try to create XMLHttpRequest object xmlHttp = new ActiveXObject(XmlHttpVersions[i]); } catch (e) {} } } // return the created object or display an error message if (!xmlHttp) { alert("Error creating the XMLHttpRequest object."); } else { return xmlHttp; } } var basiccounter ; function ServerSideValidation(contact_counter,detailed_counter,f,selection,o_name) { basiccounter = 0; //sending entity type to the server var urlEntity = "entity_type.php"; urlEntity = urlEntity+"?type="+document.getElementBYId(selection).value; urlEntity = urlEntity+"&sid="+Math.random(); checkName(urlEntity,"GET", "sel_id", "lblEntity_error"); //sending official name to the server var urlName="checkname.php"; urlName= urlName+"?q="+document.getElementBYId(o_name).value; urlName = urlName+"&sid="+Math.random(); checkName(urlName,"GET", "txtOff_name", "lblOff_error"); CheckErrors(f,basiccounter); } function checkName(url, method, id, label,f,detailed_counter) { var xmlhttp = new GetXmlHttp(); if(method == "GET") { xmlhttp.open(method, url, false); xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { if(xmlhttp .responseText != 0) { basiccounter++; document.getElementById(label).innerHTML = xmlhttp.responseText; document.getElementById(id).style.background = "pink"; } else { document.getElementById(label).innerHTML = ""; document.getElementById(id).style.background = "white"; } } } xmlhttp.send(null); } } function CheckErrors(f,error) { if(error > 0 ) { alert("found some errors on the serverside validation"); } else { f.submit(); } } The code needs to function the same way in chrome,IE,opera,firefox and netscape Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted July 30, 2009 Share Posted July 30, 2009 For firefox do you have the firebug or webdeveloper plugin installed? If so what javascript error do you receive? Do you receive any js errors at all? Quote Link to comment Share on other sites More sharing options...
napsternapster Posted July 30, 2009 Author Share Posted July 30, 2009 I have them both but webdeveloper will force me to upload the page and firebug shows no errors at all Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted July 30, 2009 Share Posted July 30, 2009 In the firebug tab named "Net" do you see the ajax script called correctly? Quote Link to comment Share on other sites More sharing options...
napsternapster Posted July 30, 2009 Author Share Posted July 30, 2009 I have no idea where to find "Net".can u please tell where to find it on the browser Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted July 30, 2009 Share Posted July 30, 2009 It's marked red in the included image [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
napsternapster Posted July 30, 2009 Author Share Posted July 30, 2009 when I include an alert() in function chechName() and it shows that the onreadystatechange is called 3 times for a single entry before getting an answer from php page Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.