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

139
Vistas
How can I make an html select form that then asks further questions depending on a user's answer?

I am a beginner JavaScript programmer trying to make an html data collecting form with JavaScript.

My goal is to …

  1. ask the user for their age and gender,
  2. then if they are Under 18y ask them their favorite school subject,
  3. if they are within 18-60y ask them their profession,
  4. if they are 60+ whether they still work.

I am unsure of then after asking the initial age question, of how to only ask certain questions depending on the user's response to this first.

Here is my code:

<html>
    <head>
    </head>
<body>
    <form>
        <label for="age">Select your age</label>
        <select id="age">
            <option value="0">Under 18</option>
            <option value="1">18-60</option>
            <option value="2">60+</option>
        </select>
        <button id="next">Next Question</button>
        <!--<select id="subject">
            <option value="0">Math</option>
            <option value="1">English</option>
            <option value="2">Science</option>
            <option value="3">History</option>
            <option value="4">Geography</option>
            <option value="5">Technology</option>
            <option value="6">Art</option>
            <option value="7">PE</option>
            <option value="8">Other</option>
        </select>
    </form-->
    <script>
        const next = document.querySelector('#next');
        const sb = document.querySelector('#age')
        next.onclick = (event) => {
            event.preventDefault();
            // show the selected index
            alert(sb.selectedIndex);
        };
        //if (sb.selectedIndex == 0) {
            
        //}
    </script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
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