I'm trying to create a webpage to help teacher determine CLO and PLO for exam questions
First user will type the keyword in text box and select the chapter CLO() function will start the AJAX the result should be a CLO Number in CLO column and PLO options in PLO column. it is my first time using AJAX so I'm not should what is wrong
this is my code
HTML Page
<! Doctype html>
<head>
<script>function CLO() {
var a=document.getElementById("keyword").value;
var b=document.getElementById("chapter").value;
if (a == ""&& b == "") {
document.getElementById("CLO").innerHTML = "";
document.getElementById("PLO").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("CLO").innerHTML = xmlhttp.responseText;
document.getElementById("PLO").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","plo.php?q1="+a+"q2="+b,true);
xmlhttp.send();
}
}
</script>
</head>
<body><form><table id="dataTable" >
<tr><th>Q </th><th>Keyword</th><th>Chapter</th><th>CLO</th> <th>PLO</th><th> Marks</th></tr>
<tr><td> 1</td><td> <input type="text" name="keyword[]" id="keyword" > </td>
<td> Chapter: <select name="chapter[]" id="chapter" onchange="CLO()"> <option value="" > </option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select></td>
<td id="CLO"> gghjgh</td> </td>
<td><select name="PLO" id="PLO"> <option > </option>
</select></td>
<td> <input type="text" name="mark[]"> </td></tr>
</table></form>
PHP Page
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
$q1 = intval($_GET['q1']);
$q2 = intval($_GET['q2']);
$con = mysqli_connect("localhost","FYP","123","FYP");
if (!$con) {
die('Could not connect: ' . mysqli_error($con));}
mysqli_select_db($con,"ajax_demo");
$level=0;
if ($q1=="Cite" || "Define "){
return $level=1;}
elseif ($q1==""){
return $level=2;
}
$sql1="SELECT * FROM SYLL_INFO WHERE C_Chapter = '".$q2."' AND Syll_pLO LIKE '%".$level."'";
$result1 = mysqli_query($con,$sql1);
while($row = mysqli_fetch_array($result)) {
echo "<td><option >". $row['Syll_PLO']. "</option></td>" ;
}
$sql2="SELECT * FROM SYLL_INFO WHERE C_Chapter = '".$q2."'";
$result2 = mysqli_query($con,$sql2);
while($row = mysqli_fetch_array($result)) {
echo "<td>". $row['Syll_CLO']."</td>" ;
}
mysqli_close($con);
?>
</body>
</html>
Appreciate your help