我正在处理一个表单,当用户输入其代码时显示数据到目前为止它在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()
答案 0 :(得分:0)
改变这个:
$makhcode=$_GET["makhcode"];
$mon=$_GET["cmbmon"];
到:
$makhcode=$_GET["u"];
$mon=$_GET["g"];