开发者

IE not rendering select options using onChange Javascript, PHP

I'm using JavaScript onChange, MySQL and PHP to display a Branch address from a list of towns which is populated from a list of counties.

It works fine in all browsers except IE (Any Version). In IE 开发者_Python百科all I get is a blank select option.

The Javascript

function getCounty(strURL) {
    if (strURL==="") {
        document.getElementById("branch").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("branch").innerHTML=xmlhttp.responseText;
            //alert(document.getElementById("branch").innerHTML=xmlhttp.responseText);
        }
    };
    xmlhttp.open("GET",strURL,true);
    xmlhttp.send(null);
}

function getBrach(strURL) {
    if (strURL==="") {
        document.getElementById("branch-addr").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("branch-addr").innerHTML=xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET",strURL,true);
    xmlhttp.send(null);
}

The Forms

<form method="post" id="addr-finder" action="">
<div class="county">
    <label>Choose County</label>
    <select name="county" id="county" onChange="getCounty('inc/findcity.php?c='+this.value)">
        <option value="Select County">Select County</option>
<?php
while($row = $result->fetch_object()) {
    echo '<option value="'.$row->address_5.'">'.$row->address_5.'</option>';
}
?>
    </select>
</div>
<div class="branch">
    <label>Choose Branch</label>
    <select name="branch" id="branch" onChange="getBrach('inc/findbranch.php?t='+this.value)">
        <option>--</option>
    </select>
</div>
</form>

The PHP

<?php
include("cfg.php");
include("functions.php");

$county = $_REQUEST['c'];
$result2 = get_town($county);
?>
    <option>Select Town</option>
<?php 
while($row2 = $result2->fetch_object()) {
?>
    <option value="<?php echo $row2->address_4 ; ?>"><?php echo $row2->address_4; ?></option>
<?php
}
?>


I did it the quick and dirty way.
using onclick instead.
You could even do both, I do that a few places for making some mobile browsers work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜