By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,970 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,970 IT Pros & Developers. It's quick & easy.

code is not working in Internet explorer

100+
P: 254
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'

Expand|Select|Wrap|Line Numbers
  1.  for html 
  2.  
  3. <html>
  4. <head>
  5. <script src="addlist.js" type="text/javascript"></script>
  6. </head>
  7. <body>
  8. <script language="javascript" type="text/javascript">
  9.  
  10. function my_submit_form() {
  11.                             obj = eval("document.form1.expbox");
  12.                             ki = 0;
  13.                             if (obj)
  14.                             {
  15.                                 var iNumItems = obj.length;
  16.                                 // create product order
  17.                                 for (i = 0; i < iNumItems; i++ )
  18.                                 {
  19.                                     if( obj.options[i].selected )
  20.                                     {
  21.                                         if (ki == 1)
  22.                                         {
  23.                                             document.form1.myExp.value += ':' + obj.options[i].value;
  24.                                         }
  25.                                         else
  26.                                         {
  27.                                             document.form1.myExp.value = obj.options[i].value;
  28.                                             ki = 1;
  29.                                         }
  30.                                     }
  31.                                 }
  32.                               }
  33.                             }
  34.  
  35. </script>
  36. <form method="get" name="form1">
  37.  <input type="hidden" name="what" value="project">
  38.     <input type="hidden" name="myExp" value="">
  39.  <table width="100%" border="1" cellspacing="0" cellpadding="0">
  40.   <tr>
  41.     <td colspan="2">&nbsp;</td>
  42.   </tr>
  43.   <tr>
  44.     <td width="36%" ><select name="expbox" style="width:350px;" multiple="multiple" size="7" onChange="my_submit_form()">
  45.     <option value="Shyam">Shyam</option>
  46.     <option value="Sunder">Sunder</option>
  47.     <option value="Mahendra">Mahendra</option>
  48.     <option value="Kumar">Kumar</option>
  49.     <option value="Rajesh">Rajesh</option>
  50.     <option value="Singh">Singh</option>
  51.     <option value="Ganesh">Ganesh</option>
  52.     <option value="Panday">Panday</option>
  53.     <option value="Mohit">Mohit</option>
  54.     <option value="Mishra">Mishra</option>
  55.     </select>      </td>
  56.     <td width="64%" align="left" ><select id="insert" style="width:150px; visibility:hidden" size="10"></select></td>
  57.   </tr>
  58.   <tr>
  59.     <td colspan="2"><input type="button" class="button" value="Search >>" onclick="addlist(document.form1.myExp.value)"></td>
  60.   </tr>
  61. </table>
  62. </form>
  63. </body>
  64. </html>
Expand|Select|Wrap|Line Numbers
  1.  for js page
  2.  
  3. var xmlHttp
  4. function addlist(str)
  5.     xmlHttp=GetXmlHttpObject()
  6.     if (xmlHttp==null)
  7.      {
  8.          alert ("Browser does not support HTTP Request");
  9.          return;
  10.      }
  11.     var url="addlist.php";
  12.     url=url+"?q="+str;
  13.     url=url+"&sid="+Math.random();
  14.     xmlHttp.onreadystatechange=stateChanged ;
  15.     xmlHttp.open("GET",url,true);
  16.     xmlHttp.send(null);
  17. }
  18. function stateChanged() 
  19.     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  20.      { 
  21.        document.getElementById("insert").style.visibility="visible";
  22.        document.getElementById("insert").innerHTML+= xmlHttp.responseText+"<br>";
  23.      } 
  24. }
  25. function GetXmlHttpObject()
  26. {
  27.     var xmlHttp=null;
  28.     try
  29.      {
  30.          xmlHttp=new XMLHttpRequest();
  31.      }
  32.     catch (e)
  33.      {
  34.          try
  35.           {
  36.               xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  37.           }
  38.          catch (e)
  39.           {
  40.               xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  41.           }
  42.       }
  43.     return xmlHttp;
  44. }
Expand|Select|Wrap|Line Numbers
  1.  for php 
  2.  
  3. <?php
  4.  
  5.     $area = 0;
  6.     $exp1 = $_GET["q"];
  7.     while ($a = each($_GET))
  8.     {
  9.         $exp1 = $_GET["q"];
  10.         $area = explode(":",$exp1);
  11.     }
  12. ?>
  13.  
  14.        <?php
  15.        while(list(,$values)=each($area))
  16.         {
  17.             echo "<option value=$values>". $values."</option>";  
  18.         }
  19.        ?>
thanks!
Jan 22 '09 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
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.
Jan 22 '09 #2

100+
P: 254
@acoder
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("Rajesh", "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
Jan 22 '09 #3

acoder
Expert Mod 15k+
P: 16,027
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.
Jan 22 '09 #4

100+
P: 254
@acoder

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.value += ':' + obj.options[i].value.

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

Thanks!
Jan 23 '09 #5

acoder
Expert Mod 15k+
P: 16,027
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.
Jan 23 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.