I am working on a form which shows the data when a user enters its code so far it was working fine with AJAX and PHP but now my need is to show the data when the user enters the code in the textbox as well selects a value from the combo box I am stuck here can anyone help me?
Here is my ajax code:
<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>
here is my 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>
here is my 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);
?>
I am using a second script as well to show the data associated with the code and its function is showyear()
Change this :
to :