I need to complete a form, according to user demand, with information from the Database (MySql).
Example:
I have the fields "Institution", "Course" and "Period". For the user, firstly, only the "Institution" option will appear, once he has selected the desired institution, the course options will appear in the field below and he will have the "Institution" and "Course" fields visible as soon as he selects the course will appear in the field below the period options and it will have the fields "Institution", "Course" and "Period" visible.
Attempt:
I used the following script to make Ajax requests:
function consulta(){
var xmlreq = CriaRequest();
var result = document.getElementById("instituicao");;
xmlreq.open("GET", 'curso.php', true);
xmlreq.onreadystatechange = function(){
(readyState=4)
if (xmlreq.readyState == 4){
if (xmlreq.status == 200){
result.innerHTML = xmlreq.responseText;
}else{
result.innerHTML = "Erro: " + xmlreq.statusText;
}
}
};
xmlreq.send(null);
}
But I did not get the desired result because I would have to make a script like this for every demand.
Question:
Is there any way I can use ONLY ONE SCRIPT for all three actions?