私の一日のトラブルは少なくとももう終わってくれることを願っています。ドロップダウンボックスが2つあります。送信した後、アクションページには最初のドロップダウンボックスの値しかありません。2番目のドロップダウンボックスは、最初のドロップダウンボックスで選択した値によって異なります。
これはヘッドセクションのajaxコードです
<script>
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;
}
function getScreen(strURL) {
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('screendiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
これがページの本文です
<form method="post" action="a.php" name="form1">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150">Device Name</td>
<td width="150"><select name="device" onChange="getScreen('finddevice.php?device='+this.value)">
<option value="">Select device</option>
<option value="1">Iphone 3</option>
<option value="2">Iphone 4</option>
<option value="3">Ipad </option>
<option value="4">android </option>
</select></td>
</tr>
<tr style="">
<td>Screen</td>
<td ><div id="screendiv"><select name="screen">
<option>Select Screen</option>
</select></div></td>
</tr>
</table>
<input type="submit" value="submit" />
</form>
次のコードを持つfinddevice.phpページを呼び出します
<? $device=$_REQUEST['device'];
$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('future');
$query="select screen from screen where device_id=$device";
$result=mysql_query($query);
?>
<select name="screen">
<option>Select Screen</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value><?=$row['screen']?></option>
<?php $row['device_id'] ?>
<? } ?>
</select>
これは完全に機能し、最初のドロップダウンボックスから値を選択すると、テーブルの値が2番目のドロップダウンボックスに表示されます。ただし、データを送信すると、$_POSTメソッドを使用してa.phpファイルの最初のドロップダウンボックスの値にのみアクセスできます。つまり、の値しか取得できませんが、$_POST['device']
からの値はありません$_POST['screen']
。私を助けてください。