Mam takyto ajax/php script na interaktivne menu SELECT. Proste ked zvoli nejaku polozku v jednom selecte, objavia sa v druhom selecte podkategorie.
Avsak funguje to aj vo FF, Opere, Chrome, ale v IE6 - IE8 to nejde vobec... Druhy select s podkategoriami je vzdy prazdny. Viete mi prosim poradit kde moze byt chyba?
Tu je cely script:
Kód:
<?php
$list1[0] = "Zvolte kategoriu";
$list1[1] = "Kategoria 1";
$list1[2] = "Kategoria 2";
if( isset($_GET['Param']) )
{
$NewData = "";
$P = (int)$_GET['Param'];
//subkategorie
$DB[1][] = "vsetky";
$DB[1][] = "subkategoria 1";
$DB[1][] = "subkategoria 2";
$DB[2][] = "NewItem2 - 1";
$DB[2][] = "NewItem2 - 2";
$row = $DB[$P];
foreach($row as $K1 => $V1)
{
$NewData .= "<option value='$K1'>$V1</option>\n";
}
echo $NewData;
exit;
}
?>
<script language="javascript">
function ajaxFunction(ID, Param)
{
//link to the PHP file your getting the data from
//var loaderphp = "register.php";
//i have link to this file
var loaderphp = "<?php echo $_SERVER['PHP_SELF'] ?>";
//we don't need to change anymore of this script
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}catch(e){
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById(ID).innerHTML = xmlHttp.responseText;
}
}
xmlHttp.open("GET", loaderphp+"?Param="+Param,true);
xmlHttp.send(null);
}
</script>
a este HTML hned pod to
Kód:
<label>Kategoria</label><select name="kateg" onchange="ajaxFunction('LBox2', this.value);" >
<?php
foreach($list1 as $K1 => $V1)
{
echo "<option value='$K1'>$V1</option>";
}
?>
</select>
<br /><br />
<label>Podkategorie</label><select name="subkateg" id="LBox2" >
<!-- OK the ID of this list box is LBox2 as refered to above -->
</select>