I'm having issues in populating a select list in IE.
The following snippet works fine in Chrome, Firefox and Safari browsers.
Are there any obvious known issues with this snippet that would prevent the information populating?
I can't figure out if it's the button IE doesn't like of the Select box.
Any ideas guys?

<table>
  <tr>
    <td><input type="text" style="width:200px" id="txtCompanySelectList">
    <input type="button" value="Company Search" onClick="prepareCompanies();">
    </td>
  </tr>
  <tr>    
    <td>
      <select name="divCompanySelectList" multiple id="divCompanySelectList" style="height:300px; width:325px; font-family:Verdana, Geneva, sans-serif;" onChange="prepareFetchListsPopulateCompanys(this.selectedIndex); tabbar.goToNextTab();">
      </select>   
   </td>
 </tr>
</table>

I can't provide a live link as it's communicating with secure data on a live database with user access privileges.

Thanks

I may need to look into your function definition. Only HTML part won't give anything because normally all browsers would use the same syntax to call script functions (and that means your HTML part won't show anything).

Thank you Taywin, here is the function that controls it:

function prepareCompanies()
		{
			var q=document.getElementById('txtCompanySelectList').value;
			getCompanies(q);
		}

Actually, I missed one...

function focus(f)
		{
			document.getElementById(f).focus(); 		
		}
	
		function prepareCompanies()
		{
			var q=document.getElementById('txtCompanySelectList').value;
			getCompanies(q);
		}
		
		function prepareFetchListsPopulateCompanys()
		{
			var t=document.getElementById('divCompanySelectList').value;
			getCompanyDetails(t);
			getContacts(t);	
			getContracts(t);	
		}

In your first code portion line 9, your HTML for 'divCompanySelectList' is a select element, but you are retrieving its value in your second code portion line 14 by using direct '.value'.

In your first code portion line 9, your HTML for 'divCompanySelectList' has onchange event calling prepareFetchListsPopulateCompanys(this.selectedIndex), but in your function in second code portion line 12, your function prototype does not have the argument in it?

Could you try the code below...

// replace this code to your 2nd code portion only starting from line 12 to 18
function prepareFetchListsPopulateCompanys(selectIdx) {
  var el=document.getElementById('divCompanySelectList');
  var t = el.options[selectIdx].value;
  getCompanyDetails(t);  // Not sure what argument this function really takes?
  getContacts(t);        // Not sure what argument this function really takes?
  getContracts(t);       // Not sure what argument this function really takes?
}

One thing... I did not add any verification of argument here because I do not want to confuse you. However, good practice would be that you should verify whether or not arguments passing to the function are valid.

Thanks Taywin,

Your way worked the same as mine in every other browser other than IE.
After a bit more debugging I think the root of the problem is the XMLHttpRequest in IE.

It's not detecting IE to select the xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP"); statement and is being treated as a non-IE browser.

It's just not populating the select box in IE:

function getCompanies(str)
{
//	alert(str);
	if (str=="")
	  {
	  document.getElementById("divCompanySelectList").innerHTML="";
	  return;
	  }
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp2=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp2.onreadystatechange=function()
	  {
	  if (xmlhttp2.readyState==4 && xmlhttp2.status==200)
		{
			document.getElementById("divCompanySelectList").innerHTML=xmlhttp2.responseText;
//alert(xmlhttp.responseText);
		}
	  }
	//xmlhttp2.open("GET","getuser.php?q="+str,true);
	xmlhttp2.open("GET","getCompanies.php?q="+str,true);
	xmlhttp2.send();

}

Oh ok. That is a way to create XML object in older version of IE. What IE version are you using in this? If you are using IE 9, you should check this link about how to use the XML object.

What needs to be changed about his code in order for it to work in IE9? Looking at that page is very vague :/

That's what Microsoft does... IE9 has different features as well. I don't have it to test because I don't use Window 7 here...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.