Thread: Problem with IE
View Single Post
  #3 (permalink)  
Old August 23rd, 2007, 09:50 AM
nick4u1lee nick4u1lee is offline
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First of all I would like thank you for spending valuable time of yours for my problem.
I made some changes like you suggested but still problem is same.

JAVASCRIPT
-----------
xmlHttp;
var loader = "Loading.......";

function test (str)
{
    alert(str);
}

function showProduct(str)
{
    if (str.length==0)
      {
          document.getElementById("product").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=stateChangedforProduct
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

function stateChangedforProduct()
{
    if (xmlHttp.readyState==1 || xmlHttp.readyState=="loading")
     {
         document.getElementById("product").innerHTML=loade r;
        document.getElementById("productpart").style.displ ay = '';
     }

    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     {
        document.getElementById("product").innerHTML=xmlHt tp.responseText;
    }
}


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 = '';
        document.getElementById("productpart").style.displ ay = 'none';
        document.getElementById("product").innerHTML='';
     }

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

function GetXmlHttpObject()
{
   xmlHttp = null;
   var success = false;

   // List of MS XMLHTTP versions - newest first
   var MSXML_XMLHTTP_PROGIDS = new Array(
       'MSXML2.XMLHttp.6.0',
       'MSXML2.XMLHTTP.5.0',
       'MSXML2.XMLHTTP.4.0',
       'MSXML2.XMLHTTP.3.0',
       'MSXML2.XMLHTTP',
       'Microsoft.XMLHTTP'
   );

   for (var i = 0; i < MSXML_XMLHTTP_PROGIDS.length && !success; i++)
   {
      try
      {
         xmlHttp = new ActiveXObject(MSXML_XMLHTTP_PROGIDS[i]);
         success = true;
         return xmlHttp;
      }
      catch (e)
      {
         xmlHttp = false;
      }
   }

   if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
   {
      try
      {
         xmlHttp = new XMLHttpRequest();
      }
      catch (e)
      {
         xmlHttp = false;
      }
   }

   return xmlHttp;
}
------------------------------------------------------
SERVER SIDE SCRIPT CALLED BY AJAX
------------------------------------------------------
<?php
$data = $_GET["q"];

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

$product = new Product;

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

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

if ($case == "product")
{
    $arrayag = $product->getProductIDandName($realdata);

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

?>
---------------------------------------------------------------
HTML CODE WRAPPER FRONTEND
---------------------------------------------------------------
<div id="category" class="subsubcategory">
<span class="normalnotice"><p>Select Category</p></span>
<select name="category" id="cat" size="6" onchange="showSubCat(this.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" onchange="showProduct(this.value+'@product')">
</select>
</div>

<div id="productpart" class="subsubcategory" style="display:none">
<span class="normalnotice"><p>Select Product</p></span>
<select name="product" id="product" size="6">
</select>
</div>
------------------------------------------------------------
Like I said it works in firefox and Opera it just IE which is not co-operating. There's several things which I want to point out
Notice that in Server Side CODE or service I am using foreach loop to populate options in select list
foreach ($array as $cur)
{
     echo '<option value="'.$array[$counter][0].'">'.$array[$counter][1].'</option>';
    $counter++;
}
it seems that IE does not understand this part like other.
also in JAVASCRIPT CODe I am using

document.getElementById('subcat').innerHTML= xmlHttp.responseText;
 I think some of wrong in these part somewhere. It's been two days and I am still working on this problem.
Once Again thanks a lot for your help.