Ajax Pageresults not loaded in IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vjayis
    New Member
    • Mar 2008
    • 134

    Ajax Pageresults not loaded in IE

    Hi

    i'm having a form which contains 2 list boxes., 1st for category and 2nd for subcategory

    the 1st list box contains the category lists., which is displayed from the database.,

    and i want to display the corresponding subcategories in the 2nd list box when the category in the 1st listbox is selected.
    So i hav called the ajax function in the onchange event of the listbox., and displayed the subcategories in the 2nd list box using xml Http request.,

    which works well in firefox but not in IE.,


    here is my code


    Code:
    <script type="text/javascript">
    var id;
    var action;
    
    
    function ajaxFunction(cat)
    {
    
    var xmlHttp;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        try
          {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (e)
          {
          alert("Your browser does not support AJAX!");
          return false;
          }
        }
      }
    xmlHttp.onreadystatechange=function()
    { 
     if(xmlHttp.readyState==4)
     { 
     	document.getElementById("change").innerHTML=xmlHttp.responseText;
     }
    }
    
    xmlHttp.open("GET","categorychange.php?catname="+cat,true);
    xmlHttp.send(null);
    
    }
    function onchangefn()
    {
    	cat_val=document.form1.category.value;
    	
    	ajaxFunction(cat_val)
    }
    </script>
    [code=php]

    //comes inside the table and category names are displayed from the database

    <select name="category" id="category" onchange="oncha ngefn()">
    <option selected="selec ted">[-------------S E L E C T-------------]</option>
    <?
    $res_cat=$ins->selectquery("s elect * from category");
    while($line_cat =mysql_fetch_ar ray($res_cat,MY SQL_ASSOC))
    {
    ?>
    <option ><? echo $line_cat['catname'];?></option>
    <?
    }
    ?>
    </select>
    [/code]

    <div id="change"></div>



    and in my categorychange. php page,by getting the category name the corresponding subcategory'a are selected from database and displayed in the <div>tag specified.,
    this is the code in the categorychange. php page.,

    [code=php]
    <?
    $res_fn=$ins->selectquery("s elect * from subcategory where catid='$catid'" );
    $i=0;
    ?>
    <select name="subcatego ry">
    <option selected="selec ted">[-------------S E L E C T-------------]</option>
    <?
    $res_fn=$ins->selectquery("s elect * from subcategory where catid='$catid'" );
    while($line_fn= mysql_fetch_arr ay($res_fn,MYSQ L_ASSOC))
    {
    ?>
    <option value="<? echo $line_fn['subcatname'];?>"><? echo $line_fn['subcatname'];?></option>
    <?
    }
    ?>
    </select>
    [/code]


    when runs in firefox it works well and the corresponding subcategory name is displayed when the category name is changed.,

    but in IE i only get the default option.,

    that is. <option selected="selec ted">[-------------S E L E C T-------------]</option>
    no corresponding list is found.,

    and even it is not displaying the subcategory list before the list item.,

    could anyone help me??

    regards
    vijay
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    is the corrrect cat sent in the IE case - so that the query is correct and you get the expected results from the database?

    kind regards

    Comment

    • vjayis
      New Member
      • Mar 2008
      • 134

      #3
      Originally posted by gits
      is the corrrect cat sent in the IE case - so that the query is correct and you get the expected results from the database?

      kind regards

      Ya probably i'm sending the correct cat value to the page.,

      And even i tested by printing the cat value in ajax page and it worked well even in IE.,
      But it is not displaying the results inside a loop. i think so.,

      thanks

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        hmmm ... i don't think that is a javascript problem when you are sure that cat is correct. i tested the following code in IE6 and FF and it worked:

        [CODE=javascript]<script type="text/javascript">
        function build_select() {
        var container = document.getEle mentById('chang e_div');

        var val = '<select><optio n value="1">1</option>'
        + '<option value="2">2</option></select>';

        container.inner HTML = val;
        }
        </script>
        <body onload="build_s elect();">
        <div id="change_div" ></div>
        </body>
        [/CODE]
        could you trace the responseText and set the innerText in IE (will not work in FF) this will show you what the responseText is ... is it what you expect to be?

        kind regards

        Comment

        • vjayis
          New Member
          • Mar 2008
          • 134

          #5
          Originally posted by gits
          hmmm ... i don't think that is a javascript problem when you are sure that cat is correct. i tested the following code in IE6 and FF and it worked:

          [CODE=javascript]<script type="text/javascript">
          function build_select() {
          var container = document.getEle mentById('chang e_div');

          var val = '<select><optio n value="1">1</option>'
          + '<option value="2">2</option></select>';

          container.inner HTML = val;
          }
          </script>
          <body onload="build_s elect();">
          <div id="change_div" ></div>
          </body>
          [/CODE]
          could you trace the responseText and set the innerText in IE (will not work in FF) this will show you what the responseText is ... is it what you expect to be?

          kind regards

          Hi

          thanks
          i ll try it out.,

          Comment

          Working...