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

142
Views
Adding Checkbox to dropdown list

I am new to JavaScript programming. My program gives me another dropdown menu based on the selection of the first dropdown menu. I am trying figure out how I can add checkbox into my dropdown so that I can check different types of fruits or vegetables.

 <script>
    window.onload = function() {
      // provs is an object but you can think of it as a lookup table
      
      var provs = {
            'Vegetable': ['Broccoli', 'Cabbage','Carrot'],
            'Fruit': ['Tomato', 'Apple','Orange']
          
          },
          // just grab references to the two drop-downs
          food_select = document.querySelector('#food'),
          type_select = document.querySelector('#type');
    
      // populate the drop-down
      setOptions(food_select, Object.keys(provs));
      // populate the town drop-down
      setOptions(type_select, provs[food_select.value]);
      
      // attach a change event listener to the drop-down
      food_select.addEventListener('change', function() {
        // get the towns in the selected province
        setOptions(type_select, provs[food_select.value]);
      });
        
      function setOptions(dropDown, options) {
        // clear out any existing values
        dropDown.innerHTML = '';
        // insert the new options into the drop-down
        options.forEach(function(value) {
          dropDown.innerHTML += '<option name="' + value + '">' + value + '</option>';
        });
      }  
    };
    
    </script>
    <body>
    <select id="food"></select><br><br><br>
    <select id="type"></select>
    
    <body>
about 4 years ago · Santiago Gelvez
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!