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

146
Views
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
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!