Thread: Problem with IE
View Single Post
  #1 (permalink)  
Old August 22nd, 2007, 12:10 PM
nick4u1lee nick4u1lee is offline
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with IE

This is my first time asking for help in any forum and I am not that good with AJAX. I would really appreciate any comments or suggestions.
Here is the problem.
I am trying to create one dependent dynamic list first it loads category from database(DB) then based on category selected it will pull subcategory list from DB and same for product name. Well I finished all parts including server side coding and Javascript coding and worked perfectly in Firefox as well Opera but not in IE. Here is the code.

Javascript
-------------------------------------------
<script type="text/javascript">
var xmlHttp;
var loader = "Loading.......";

function showSubCat(str)
{
  if (str.length==0)
  {
    document.getElementById("subcat").innerHTML=""
    return
  }

  xmlHttp=GetXmlHttpObject()

  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request")
    return
  }

  var url="sendproduct.php"
  url=url+"?q="+str
  url=url+"&sid="+Math.random()
  xmlHttp.onreadystatechange=stateChanged
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function stateChanged()
{
  if (xmlHttp.readyState==1 || xmlHttp.readyState=="loading")
  {
    document.getElementById("subcat").innerHTML=loader ;
    document.getElementById("subcategory").style.displ ay = '';
  }

  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  {
   document.getElementById("subcat").innerHTML=xmlHtt p.responseText;
  }
}

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
  // Firefox, Opera 8.0+, Safari
   xmlHttp=new XMLHttpRequest();
  }

  catch (e)
  {
   // Internet Explorer
  try
  {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }

  catch (e)
  {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}

return xmlHttp;
}
------------------------------------------------------------
HTML
------------------------------------------------------------
<?php
$product = new Product;
$array = $product->getSubCategoryInfo ();
?>
<div id="category" class="subsubcategory">
<span class="normalnotice"><p>Select Category</p></span>
<select name="category" id="cat" size="6" onchange="showSubCat(document.getElementById('cat' ).value+'@subcat')">
<?php
$counter = 0;
foreach ($array as $cur)
{
    echo '<option value="'.$array[$counter][0].'">'.$array[$counter][1].'</option>';
    $counter++;
}
?>
</select>
</div>

<div id="subcategory" class="subsubcategory" style="display:none">
<span class="normalnotice"><p>Select Sub-category</p></span>
<select name="subcategory" id="subcat" size="6">
</select>
</div>

<div id="product" class="subsubcategory" style="display:none">
<span class="normalnotice"><p>Select Product</p></span>
<select name="product" id="product" size="6">
    <option>Too Many Choices</option>
</select>
</div>
---------------------------------------------------------------
SERVER SIDE SCRIPT WHICH AJAC CALLS
sendproduct.php
---------------------------------------------------------------
<?php
$data = $_GET["q"];

list($realdata, $case) = split("@", $data);//split

$product = new Product;

if ($case == "subcat")
{
    $product = new Product;
    $array = $product->getSubSubCategoryInfo($realdata);

    $counter = 0;
    foreach ($array as $cur)
    {
       echo '<option value="'.$array[$counter][0].'">'.$array[$counter][1].'</option>';
        $counter++;
    }
}

if ($case == "product")
{

}

?>
----------------------------------------------------------
Please note that product has been completed yet.
It seems like there's probelm in XMLHTTP variable since it works in Firefox that's why. Please give me any suggestion.