Connecting Tech Pros Worldwide Help | Site Map

Problem with IE in javascript, tested ok with Firefox,Opera, Safar &,Chrome

Newbie
 
Join Date: Sep 2009
Posts: 1
#1: Sep 7 '09
I have two selection list, which the second one populates depending at the selection of the first.

Expand|Select|Wrap|Line Numbers
  1.       <select id="category" onchange="getRegions('1',this.value,'region','imagediv1')" >
  2.         <option selected="selected" value="" > Please Select Category</option>
  3.          <?php
  4.          do {  
  5.           print ("<option value=\"".$row_Recordset1['id_categories_pk']."\"");
  6.  
  7.           print(">".$row_Recordset1['category_name']."</option>");
  8.  
  9.         } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  10.               $rows = mysql_num_rows($Recordset1);
  11.                   if($rows > 0) {
  12.                       mysql_data_seek($Recordset1, 0);
  13.                       $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  14.                   }
  15.         ?>
  16.       </select>
Second one
Expand|Select|Wrap|Line Numbers
  1. <select id="region" onChange="getImage('category',this.value,'imagediv1')" >
  2.     <option selected value="">Select Category First</option>
  3.      </select></div></td>

Expand|Select|Wrap|Line Numbers
  1. function getRegions(languageId,categoryId,element) {        
  2.  
  3.         enable_list(element);
  4.         var strURL="regions.php?language="+languageId+"&category="+categoryId;
  5.  
  6.         var req = getXMLHTTP();
  7.  
  8.         if (req) {
  9.  
  10.             req.onreadystatechange = function() {
  11.                 if (req.readyState == 4) {
  12.                     // only if "OK"
  13.                     if (req.status == 200) {                        
  14.                         document.getElementById(element).innerHTML=req.responseText;                        
  15.                     } else {
  16.                         alert("There was a problem while using XMLHTTP:\n" + req.statusText);
  17.                     }
  18.                 }                
  19.             }            
  20.             req.open("GET", strURL, true);
  21.             req.send(null);
  22.         }
  23.  
  24.     }
The problem ( only in IE), the second list is complete blank.I think the problem is at getRegions('1',this.value,'region') with this.value or with getElementById.

What i have to change to above code so the IE will be ok?
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Sep 8 '09

re: Problem with IE in javascript, tested ok with Firefox,Opera, Safar &,Chrome


This is an IE bug: see here. However, don't use outerHTML. Use a loop to add each option individually.
Reply