Jump to content

Ie Problem When Creating Options For The Select Obj With Javascript


stijn0713

Recommended Posts

Based on the faculty they select, different programs should appear in another select dropdown list.

 

I tried 2 methods, neither of them work in IE... they do work in all other browsers.

 

First method tried:

 

on the server side:

 

if(isset($_GET['fac'])){

$fac = $_GET['fac'];

$display = "<option value=''>Studierichting:</option>";

foreach ($richtingen as $num => $array){

foreach ($array as $faculteit => $richting){

if($faculteit == $fac){
$display .= '<option value ="'.$richting.'">'.$richting.'</option>';
}
}
}




echo $display;

}

 

in javascript:

 

function dropdownlist(listindex)
{

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)
{
//alert(xmlhttp.responseText);
document.getElementById("studierichting").innerHTML=xmlhttp.responseText; //--> doesn't work like this in IE
}
}

var queryString = "?fac=" + listindex;

xmlhttp.open("GET","welke_fac.php" + queryString,true);
xmlhttp.send();
}

 

 

Second try:

 

server side:

if(isset($_GET['fac'])){

$fac = $_GET['fac'];

$display = '';

foreach ($richtingen as $num => $array){

foreach ($array as $faculteit => $richting){

if($faculteit == $fac){
$display .= $richting.',';
}
}
}

echo $display;
}

 

js:

 

var zipstring = xmlhttp.responseText;
var ziparray = zipstring.split(",");

//alert(ziparray.length);

for(var i=0; i < ziparray.length-1; i++) {

studierichting.options[i] = new Option(ziparray[i],ziparray[i]);
}

 

according to this site it should prevent the bug in IE:

http://support.micro...kb;en-us;276228 . however, also this method works for every browser except IE...

 

Thoughts?

 

Thanks in advance

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.