GithubHelp home page GithubHelp logo

Dependent Dropdown about choices HOT 1 CLOSED

choices-js avatar choices-js commented on April 29, 2024
Dependent Dropdown

from choices.

Comments (1)

jshjohnson avatar jshjohnson commented on April 29, 2024 1

This is technically already possible. I've made an example below for you:

<label for="cities">States</label>
<select name="cities" id="cities" placeholder="Choose a state">
    <option value="Texas">Texas</option>
    <option value="Chicago">Chicago</option>
    <option value="New York">New York</option>
    <option value="Washington">Washington</option>
    <option value="Michigan">Michigan</option>
</select>

<label for="boroughs">Boroughs</label>
<select name="boroughs" id="boroughs" placeholder="Choose a borough">
    <option value="The Bronx">The Bronx</option>
    <option value="Brooklyn">Brooklyn</option>
    <option value="Manhatten">Manhatten</option>
    <option value="Queens">Queens</option>
    <option value="Staten Island">Staten Island</option>
</select>
document.addEventListener('DOMContentLoaded', function() {
    var cities = new Choices(document.getElementById('cities'), {
        callbackOnChange: function(value) {
            if(value === 'New York') {
                boroughs.enable();
            } else {
                boroughs.disable();
            }
        }
    });

    var boroughs = new Choices(document.getElementById('boroughs')).disable();
});

You could of course do some fancier validation on the value but you get the idea!

Thanks

from choices.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.