In the code below , a user selects a subject and the script below checks the subject selected and displays a list of topics options based on the subject the user selected.So my question is , is there a way to make the form in the script functional .in that is there a way to get the specific value of a topic the user selects.
<script>
function showUser() {
var subject=document.getElementById('subject').value;
if (subject == "maths") {
document.getElementById("form").innerHTML = "<?php echo"<form>
<select id='topic'onchange='showuser()'>
<option value='algebra'>algebra</option>
<option value='calculus'>calculus</option>
</select></form>";?>";
var school= document.getElementById("topic").value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","get.php?subject="+subject+"& topic="+topic,true);
xmlhttp.send();
return;
}
else if (subject =="English"){
document.getElementById("form").innerHTML = "<?php echo"<form>
<select id='topic'onchange='showUser()'>
<option value='verbs'>verbs</option>
<option value='nouns'>nouns</option>
</select></form>";?>";
var topic= document.getElementById("topic").value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","get.php?subject="+subject+"& topic="+topic,true);
xmlhttp.send();
return;
}
else {
document.getElementById("form").innerHTML ="Invalid choice";
}
}
</script>