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

190
Vistas
Activate TextBox if another option is selected in PHP

I have two dropdown lists and I want for example, if value=fetch selected then show second dropdown but it doesn't work.

I have tried with call external PHP file but I was stuck again. I think that the problem is when I call the on change method but I don't know what to type.

function action(dropdown) {

    var value = dropdown.options[dropdown.selectedIndex].value;
    if (value == 'Fetch'){
        document.getElementById("student_list").style.display = "block";
        document.getElementById("subject_list").style.display = "none";
    }

    if(value == 'Count'){
       document.getElementById("student_list").style.display = "block";
    }
    if(value == 'Percentage'){
       document.getElementById("subject_list").style.display = "block";
    }
}

<body>

  <div class="main_container">
    
        <form method="post">
            <select name="action" id ="fetch"  onchange="action(this.value);">
                <option value="" id="action">--Select Action--</option>
                <option value="Fetch">Fetch</option>
                <option value="Count">Count</option>
                <option value="Percentage">Percentage</option>
            </select>
            <select name="student_name" id ="student_list"  onChange="" style="display:none;">  <!--onchange="getNext(this.value);" -->
                <option value="">--Select  Action --</option>
                <option value="All">All Students</option>
                <option value="NameS">Student Name</option>
            </select>               
        
</form>
</div>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You cannot use a function named "action" please see https://stackoverflow.com/a/37590405/5391965

You should retrieve your values within the function instead of passing it in parameters like so :

function displayStudentList(dropdown) {
    let subject = document.getElementById("subject_list").value;
    if (subject === 'Fetch') {
        document.getElementById("student_list").style.display = "block";
        document.getElementById("subject_list").style.display = "none";
    }
    if (subject === 'Count') {
        document.getElementById("student_list").style.display = "block";
    }
    if (subject === 'Percentage') {
        document.getElementById("subject_list").style.display = "block";
    }
}
<div class="main_container">
    <form method="post">
        <select name="action" id="subject_list"  onchange="displayStudentList()">
            <option value="" id="action">--Select Action--</option>
            <option value="Fetch">Fetch</option>
            <option value="Count">Count</option>
            <option value="Percentage">Percentage</option>
        </select>
        <select name="student_name" id ="student_list"  onChange="" style="display:none;">  
            <!--onchange="getNext(this.value);" -->
            <option value="">--Select  Action --</option>
            <option value="All">All Students</option>
            <option value="NameS">Student Name</option>
        </select>
    </form>
</div>

about 4 years ago · Juan Pablo Isaza 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