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

Recommended Answers

All 4 Replies

Napster^2,

Not sure but it may be var xmlhttp = new GetXmlHttp(); .

Typically GetXmlHttp() would return an xmlHttpRequest object, so new would not be required in the call. Of couse I can't tell for certain without seeing the GetXmlHttp function but it's possible that FF is sensitive to this.

Airshow

Here is function
GetXmlHttp

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;
	}
}

I've not seen that particular version of GetXmlHttp before but it looks good.

Certainly delete new from var xmlhttp = new GetXmlHttp(); .

Airshow

Just spotted something else. There's a rodent space in the line if(xmlhttp .responseText != 0) , which might cause FF to baulk.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.