newbie14 0 Posting Pro

Dear All,
I have one combo box where upon change will call ajax function to fill another combo box below. All works fine in IE but when I test it in chrome and firefox I have one minor problem. The problem is here echo "<option value=".$haulierID.">".$row1."</option>";. I notice in chrome and firefox the value= is empty but not in IE. What could be the problem?

Below is my ajax.

<script type="text/javascript">
function getHaulier(str)
{
differentiator=Math.floor(Math.random()*50000);
if (str=="")
  {
  document.getElementById("cbHaulier").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("cbHaulier").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getHaulierNotInClient.php?q="+str+"d="+differentiator,true);
xmlhttp.send();
}

function checkEnter(e)
{ //e is event object passed from function invocation
				var characterCode;
				// literal character code will be stored in this variable
			
				if(e && e.which)
				{ //if which property of event object is supported (NN4)
				e = e
				characterCode = e.which //character code is contained in NN4's which property
				}
				else
				{
				e = event
				characterCode = e.keyCode //character code is contained in IE's keyCode property
				}
			
				if(characterCode == 13)
				{ //if generated character code is equal to ascii 13 (if enter key)
				document.forms[0].submit() //submit the form
				return false 
				}
				else
				{
				return true 
				}
}
function validateForm() 
{
			//alert("TEST");
			//Get the controls
			//var haulierIDControl = document.getElementById("haulierID");
			//var positionIDControl = document.getElementById("positionID");
      
      //alert("haulierIDControl : "+haulierIDControl.value);
      //alert("nameControl : "+nameControl.value);
			
			
			
			//Create expressions
			var isNumeric = /^[0-9]+$/;
			var isLetters = /^[a-zA-Z]+$/;
			var isEmail = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
			
			//Cheack each one and if it fails, set an appropriate error message
			var gotHaulierIDError="false";
			var gotPositionIDError="false";
		
			
			/*if(haulierIDControl.value<1)
			{
				haulierIDError.innerHTML = " * Select A Haulier";
				gotHaulierIDError="true";
			}
			else
			{
				haulierIDError.innerHTML = "";
				gotHaulierIDError="false";
			}
			
			if(positionIDControl.value<1)
			{
				positionIDError.innerHTML = " * Select A Position";
				gotPositionIDError="true";
			}
			else
			{
				positionIDError.innerHTML = "";
				gotPositionIDError="false";
			}
			
			
			
			//If any errors occurred, return false, otherwise true
			if(gotHaulierIDError=="true" || gotPositionIDError=="true" || gotUserNameError=="true" || gotUserPasswordError=="true" || gotUserFullNameError=="true" || gotUserEmailError=="true" || gotUserContactNumberError=="true")
				return false;
			else 
				return true;	*/			
};
    </script>

Below is my getHaulierNotInClient.php

<?php 
require_once('config.php');
$q=$_GET["q"];

if($q>0)
{
	$link = mysql_connect(dbHost, dbUser, dbPassword);
	if(!$link)
	{
			die('Failed to connect to server: ' . mysql_error());
	}
		
	//Select database
	$db = mysql_select_db(dbDatabase);
	if(!$db) 
	{
			die("Unable to select database");
	}
	
	$selectQuery1 ="Select haulierID,haulierName From tblHaulier Order By tblHaulier.haulierName"; 
	$result1 = mysql_query($selectQuery1);
	$n1 = mysql_num_rows($result1);
	 
	echo "<select class='select' id='haulierID' name='haulierID' >";
	echo "<option value=0>-Select Haulier-</option>";
	while($row1 = mysql_fetch_array($result1, MYSQL_ASSOC))
	{
		$haulierID = $row1['haulierID'];
		echo "\nHaulierID".$haulierID;
		$selectQuery2 ="Select haulierID,clientID From tblClientHaulier Where clientID='".$q."' And haulierID='".$haulierID."'"; 
	  $result2 = mysql_query($selectQuery2);
	  //$row2 = mysql_fetch_array($result2, MYSQL_ASSOC);
	  $n2 = mysql_num_rows($result2);
	  //echo "<br>selectQuery2 ".$selectQuery2;
	  //echo "<br>n2 ".$n2;
	  if($n2>0)
	  {
	  	
	  }
	  else
	  {
	  	echo "<option value=".$haulierID.">".$row1['haulierName']."</option>";
	  }
		
	}
	echo "</select>";
									 
	
	mysql_close($link);
}

?>
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.