<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>www.tutorials.de</title>
<meta name="author" content="Quaese" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
<!--
var resObjekt = null;
var strStart = "<select name=\"gemeinde\">\n<option value=\"0\">- wählen -</option>\n</select>\n";
function makeRequest() {
// Falls noch ein Request-Objekt existiert -> zunächst beenden
if(resObjekt && resObjekt.readyState){
resObjekt.abort();
resObjekt = false;
}
if(window.XMLHttpRequest){ // Mozilla, Safari,...
resObjekt = new XMLHttpRequest();
if (resObjekt.overrideMimeType) {
resObjekt.overrideMimeType('htm/html');
// zu dieser Zeile siehe weiter unten
}
}else if(window.ActiveXObject){ // IE
try{
resObjekt = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
resObjekt = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
if(!resObjekt){
alert('Kann keine XMLHTTP-Instanz erzeugen');
return false;
}
return true;
}
function sndReq(objSel){
if(objSel.selectedIndex > 0){
makeRequest();
resObjekt.open('get','laender.php?wo='+objSel.selectedIndex,true);
resObjekt.onreadystatechange = handleResponse;
resObjekt.send(null);
}else{
document.getElementById("hs").innerHTML = strStart;
}
}
function handleResponse(){
if(resObjekt.readyState == 4){
if (resObjekt.status == 200){
document.getElementById("hs").innerHTML = resObjekt.responseText;
}
}
}
//-->
</script>
</head>
<body>
<br />
<script language="JavaScript" src="gemeinden.js"></script>
<form name="f" action="test.php" method="post">
<select name="kanton" size="1" onchange="sndReq(this);">
<option value="0" selected="selected">- wählen -</option>
<?php
$res = mysql_query("SELECT id,kanton FROM tbl_kantone ORDER BY kanton ASC");
while($dsatz = mysql_fetch_array($res))
{
$id = $dsatz['id'];
$kanton = $dsatz['kanton'];
echo '<option value="'.$id.'">'.$kanton.'</option>';
}
?>
</select>
<span id="hs">
<select name="gemeinde">
<option value="0">- wählen -</option>
</select>
</span>
<input type="submit" />
</form>
</body>
</html>