I have a 'question' table that has the maximum of 10 options with 1 answer type which is declared in the answer_type column.
Firstly, this is my code for displaying dropdowns based on user input in the textbox. And these generated dropdowns contains the questions
<script>
$(document).ready(function(){
$("#execute").click(function(){
var numQ = +$('#q_num').val();
//Loop--
for(var ctr=0; ctr < numQ; ctr++){
var str = load_questions();
$("#divQuestions").append(str);
}
});
});
</script>
After inputting number of questions, its needed to select a category or subcategory to actually generate the number of dropdowns because all questions are under a category or subcategory.
function load_questions(){
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php??main=1&subcategory="+document.getElementById("subcategorydd").value +"&cnt="+document.getElementById("q_num").value,false);
xmlhttp.send(null);
document.getElementById("question").innerHTML=xmlhttp.responseText;
}
How do I do an onclick trigger that will also display the answer type when i select a question on the dropdown and display it whatever the answer_type is for example checkbox, radiobutton?
<script>
$('#group').change(function (){
$.ajax({
type: "GET",
url: "ajax.php??main=1&subcategory",
data: {main:'1', subcategory:$('#subcategorydd').val(), cnt:$('#q_num').val()},
dataType: "html", //expect html to be returned
async:false,
success: function(response){
$('#divQuestions').append= response;
get_table();
}
});
});
</script>
and from php side
foreach($group->result() as $grp){
echo '<option value="'.$grp->SubNum.'">'.$grp->SubCategory.'</option>';
}
or you can submit your own query style