So I'm getting used to using AJAX, I have a simple form where the user enters a number (referring to a job card) and then I want to use AJAX to return the status and priority of that job card when the user clicks update.
The status field successfully updates with the code below.
Here is the html form:
<div class="JobCard">
No. <input id="num" type="text">
Status: <input id="status" type="text" readonly>
Priority: <input id="priority" type="text" readonly>
<input type="button" value="Update" onclick='showStatus(getElementById("num").value)'>
</div>
My java script:
<script>
function showStatus(num) {
if (num == "")
{
document.getElementById("status").value = "";
return;
}
else
{
xmlhttp = new XMLHttpRequest();
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("status").value = xmlhttp.responseText;
}
};
xmlhttp.open("GET","getStatus.php?q="+num,true);
xmlhttp.send();
}
</script>
And also my getStatus.php file:
<?php
require_once("../functions.php");
$num = sanitizeString($_GET['q']);
$result = queryMySql(" SELECT `Status` FROM JobCardHead WHERE JobCardNum = '$num' ");
$row = $result->fetch_assoc();
$status = $row['Status'];
echo $status ;
?>
My question is how can I extend this so that the Priority field also updates. I know that I could create a new function showPriority() and and new file getPriority.php but I plan to add many more fields so I wonder if theres a more efficient way.