Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda