動的に変更できるドロップダウン メニューを作成するための優れたチュートリアルを見つけました。
ここにリンクがあります。
ここにデモがあります
http://roshanbh.com.np/dropdown/
コードを少しいじっていて、状態を選択する部分をスキップしています。
これがfindCity.phpファイルです
<!--//---------------------------------+
// Developed by Roshan Bhattarai |
// http://roshanbh.com.np |
// Contact for custom scripts |
// or implementation help. |
// email-nepaliboy007@yahoo.com |
//---------------------------------+-->
<?
#### Roshan's Ajax dropdown code with php
#### Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com
#### if you have any problem contact me at http://roshanbh.com.np
#### fell free to visit my blog http://php-ajax-guru.blogspot.com
?>
<? $country = $_GET['country'];
$link = mysql_connect("snip","snip","snip");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('snip');
$query="SELECT city FROM location WHERE country='$country'";
$result=mysql_query($query);
?>
<select name="city">
<option>Select City</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value><?=$row['city']?></option>
<? } ?>
</select>
国変数でfindCity.phpを開くと正常に動作します
http://globatum.com/admin/findCity.php?country=United%20States
国リストの値がこの関数を適切に通過しない理由がわかりません
function getCity(country) {
var strURL="findCity.php?country="+ country;
var req = getXMLHTTP();
if (req) {
req.onreadycountrychange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('citydiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
ここに何かアイデアはありますか?
追記事項
function getXMLHTTP() { //function to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}