Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda