Search code examples
javascripthtmlcssinputinnerhtml

Dynamically adding HTML using .innerHTML (formatting issue in IE7)


I have a select dropdown that when updated takes the new variable and dynamically updates the div directly below it.

HERE is my select input:

<select name='region_name' onchange='showDistrict(this.value)'>

here is my javascript that controls the dynamic stuff:

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

The page getdistrict.php?q= does another MySQL call and loops out info into the div "district_div" MY PROBLEM IS... that div region does not stretch correctly in IE 7. So my dynamic data overlays everything below it.

When I look at the source with firebug I don't even see the new html from innerHTML so I am not sure this is a css issue or something having to do with .innerHTML


Solution

  • do not set any width or height for this DIV, or set only min-width min-height, and you can also set overflow:hidden for this DIV