Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
How to display data from database with onclick in dropdown?

enter image description here

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?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

<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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!