0

hi... i'm a new member of daniweb

i have a problem in setting 2 comboboxes.
i want to populate the second combobox based on first combobox value.

i already have the code running well in firefox and chrome.
but the code is not working in IE.

can anyone please help me?
Thanx.

2
Contributors
7
Replies
9
Views
5 Years
Discussion Span
Last Post by hptchen
0

this is my code..

<script>
function checkprovince()
{
    var province=document.getElementById("province").value;
    var xmlhttp;

    if(window.XMLHttpRequest)
    {
        xmlhttp=new window.XMLHttpRequest();

    }
    else
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLTTP");
    }

    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState == 4 && xmlhttp.status ==200)
        {
            document.getElementById("city").innerHTML= xmlhttp.responseText;
        }
    }

    xmlhttp.open("POST","file.php",false);
    xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
    xmlhttp.send("province="+province);
}
</script>

<select name="province" id="province" onchange="checkprovince()">
<option value=0 selected="selected">-choose province-</option>
<?php
$getprovince=mysql_query("select * from city, province where city.id_prov=province.id_prov group by province.id_prov") or die("error");
$row=mysql_num_rows($getprovince);

for($x=0;$x<$row;$x++)
{
    $provincename=mysql_result($getprovince,$x,"province_name");
    $idprov=mysql_result($getprovince,$x,"id_prov");
    print "<option value=$idprov>$provincename</option>"; 
}
?>
</select>
<select id="city" name="city" onfocus="checkprovince()">
<option value="0" selected="selected">-choose city-</option>
</select>

then in file.php

<?php
if(isset($_POST["province"]))
{
    $provinsi=$_POST["province"];
    include("config/koneksi.php");
    $getcity=mysql_query("select * from city where id_prov='".$province."'");
    $row=mysql_num_rows($getcity);
    print "<option value=0 selected='selected'>-choose city-</option>";
    for($x=0;$x<$row;$x++)
    {
        $idcity=mysql_result($getcity,$x,"id_city");
        $cityname=mysql_result($getcity,$x,"city_name");
        print "<option value=$idcity>$cityname</option>";

    }

}

?>
0

i tried to put window.alert below line 14, and it didn't come out also

0

thanx pritaeas..
but i already fixed it with another method..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.