我正在开发一个表单,该表单在用户输入其代码时显示数据,到目前为止它在 AJAX 和 PHP 上运行良好,但现在我需要在用户在文本框中输入代码时显示数据并从中选择一个值我被困在这里的组合框有人可以帮助我吗?
这是我的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 showsub(strURL) {
// var strURL="subjsele.php?makhcode="+document.nigran.makhcode.value+"&mon="+document.nigran.mon.value;
var u = document.getElementByID('makhcode').value;
var g = document.getElementByID('cmbmon').value;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('subcomp').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET","getuser.php?u="+u+"&g="+g, true);
req.send(null);
}
}
</script>
这是我的html
<tr>
<td align="right" width="58px"><label class="" for="element_1"><font size="3px"><b>Code</b></font></label></td><td><input id="makhcode" name="makhcode" onkeyup="showyear('makhsele.php?makh='+this.value)" onkeypress="showsub()" type="text" maxlength="6" size="6" value=""/></td><td><label class="description" align="right" for="element_1">Month</label></td><td><select id="cmbmon" name="cmbmon" class="" onchange="showsub()" style="font-size:14px;">
<option value="">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</td>
</tr>
这是我的 php
<?php
$makhcode=$_GET["makhcode"];
$mon=$_GET["cmbmon"];
$con = mysql_connect('localhost', 'cepheisys', 'rajF@1998');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("pts_root", $con);
$subqry = mysql_query("SELECT * FROM subject WHERE compulsory='1'")or die(mysql_error());
echo "<table>";
while($fetch = mysql_fetch_array($subqry));
{
$sscode = $fetch["code"];
$csubqry = mysql_query("SELECT * FROM nigstat WHERE makhcode='".$makhcode."' AND subcode='".$sscode."'") or die(mysql_error());
$mmonval = $csubqry["mon1"];
echo "<tr>";
echo "<td>.$mmonval.</td><td></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='200px'><font color='#FF0033'><strong>".$fetch[name]."</strong></td><td><input name='s_".$fetch[code]."' type='text' size='1' maxlength='2' value='$mmonval'></td><input type='hidden' name='$mmonval' size='3' maxlength='3'>";
echo "</tr>";
}
mysql_close($con);
?>
我也在使用第二个脚本来显示与代码相关的数据,它的函数是 showyear()