954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Dynamic Select Box Population in IE issue

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

Roy Murphy
Newbie Poster
12 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
 

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).

Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
 

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

function prepareCompanies()
		{
			var q=document.getElementById('txtCompanySelectList').value;
			getCompanies(q);
		}
Roy Murphy
Newbie Poster
12 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
 

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);	
		}
Roy Murphy
Newbie Poster
12 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
 

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.

Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
 

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();

}
Roy Murphy
Newbie Poster
12 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
 

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.

Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
 

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

Jowy2000
Newbie Poster
1 post since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

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...

Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: