code is not working in Internet explorer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mukeshrasm
    Contributor
    • Nov 2007
    • 254

    code is not working in Internet explorer

    Hi

    I am using AJAX to display the value in selection/list box. this code is working fine in Firefox Mozila browser but it is not working in Internet Explorer so please tell me how this will work in both'

    Code:
     for html 
    
    <html>
    <head>
    <script src="addlist.js" type="text/javascript"></script>
    </head>
    <body>
    <script language="javascript" type="text/javascript">
    
    function my_submit_form() {
                                obj = eval("document.form1.expbox");
                                ki = 0;
                                if (obj)
                                {
                                    var iNumItems = obj.length;
                                    // create product order
                                    for (i = 0; i < iNumItems; i++ )
                                    {
                                        if( obj.options[i].selected )
                                        {
                                            if (ki == 1)
                                            {
                                                document.form1.myExp.value += ':' + obj.options[i].value;
                                            }
                                            else
                                            {
                                                document.form1.myExp.value = obj.options[i].value;
                                                ki = 1;
                                            }
                                        }
                                    }
                                  }
                                }
    
    </script>
    <form method="get" name="form1">
     <input type="hidden" name="what" value="project">
        <input type="hidden" name="myExp" value="">
     <table width="100%" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td width="36%" ><select name="expbox" style="width:350px;" multiple="multiple" size="7" onChange="my_submit_form()">
        <option value="Shyam">Shyam</option>
        <option value="Sunder">Sunder</option>
        <option value="Mahendra">Mahendra</option>
        <option value="Kumar">Kumar</option>
        <option value="Rajesh">Rajesh</option>
        <option value="Singh">Singh</option>
        <option value="Ganesh">Ganesh</option>
        <option value="Panday">Panday</option>
        <option value="Mohit">Mohit</option>
        <option value="Mishra">Mishra</option>
        </select>      </td>
        <td width="64%" align="left" ><select id="insert" style="width:150px; visibility:hidden" size="10"></select></td>
      </tr>
      <tr>
        <td colspan="2"><input type="button" class="button" value="Search >>" onclick="addlist(document.form1.myExp.value)"></td>
      </tr>
    </table>
    </form>
    </body>
    </html>
    Code:
     for js page
    
    var xmlHttp
    function addlist(str)
    { 
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
         {
             alert ("Browser does not support HTTP Request");
             return;
         }
        var url="addlist.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==4 || xmlHttp.readyState=="complete")
         { 
           document.getElementById("insert").style.visibility="visible";
           document.getElementById("insert").innerHTML+= xmlHttp.responseText+"<br>";
         } 
    }
    function GetXmlHttpObject()
    {
        var xmlHttp=null;
        try
         {
             xmlHttp=new XMLHttpRequest();
         }
        catch (e)
         {
             try
              {
                  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
              }
             catch (e)
              {
                  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
          }
        return xmlHttp;
    }
    Code:
     for php 
    
    <?php
    
        $area = 0;
        $exp1 = $_GET["q"];
        while ($a = each($_GET))
        {
            $exp1 = $_GET["q"];
            $area = explode(":",$exp1);
        }
    ?>
    
           <?php
           while(list(,$values)=each($area))
            {
                echo "<option value=$values>". $values."</option>";  
            }
           ?>
    thanks!
    Last edited by Dormilich; Jan 22 '09, 10:44 AM. Reason: fixed [code] tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    This is a similar problem to the one in this thread. See my reply there or return the select element from PHP rather than having the select already in the HTML code.

    Comment

    • mukeshrasm
      Contributor
      • Nov 2007
      • 254

      #3
      Originally posted by acoder
      This is a similar problem to the one in this thread. See my reply there or return the select element from PHP rather than having the select already in the HTML code.
      Hi
      I knew that you will take this so i want to concate the result in the second list/select box. say i seleced "kumar" and clicked search button and then i made multiple selection("Raje sh", "Singh") and clicked seach so in second list box "kumar" along with "Rajesh" and "Singh" should display.

      And if I use select element in php then it concat on list/selection with other. that's why i used in the html code

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You can give the td element on line 56 an id and then set its innerHTML property to the select element (with options) returned from PHP.

        Having said that, looking at your code, there's no need for Ajax at all. What the PHP code is doing could be done in the my_submit_form( ) function.

        Comment

        • mukeshrasm
          Contributor
          • Nov 2007
          • 254

          #5
          Originally posted by acoder
          You can give the td element on line 56 an id and then set its innerHTML property to the select element (with options) returned from PHP.

          Having said that, looking at your code, there's no need for Ajax at all. What the PHP code is doing could be done in the my_submit_form( ) function.

          Hi! you mean in my_submit_form( ) function i should remove the line 21

          document.form1. myExp.value += obj.options[i].value with document.form1. selectelemt.val ue += ':' + obj.options[i].value.

          if not then what and where i need to change in this funtion.

          Thanks!

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            You get access to the selected options in my_submit_form( ), so you can either create options out of them, or create the HTML strings to use to set the innerHTML property of the containing element.

            Comment

            Working...