Giter Site home page Giter Site logo

cascading-dropdown's Introduction

CascadingDropdown.js

A vanilla javascript (ie. no additional libraries needed) plugin for cascading dropdown menus. This allows the values of an HTML <select> to be dependent on the value selected in a parent <select> element.

Demo

Demo

Usage

1. Include CascadingDropdown.js

<script src="CascadingDropdown.js"></script>

2. Add markup to <select>

  • id: each <select> must have an id defined.
  • class="cascadingDropdown": customizable in the plugin intialization options below.
  • data-select-message="...": the text displayed in the default option.
  • data-url: the URL for ajax requests.
  • data-parent-fields: comma delimited list of ids that the current field is dependent on.

For example:

<h2>Car Inventory:</h2>
<form>
  <select id="Year" name="Year" class="cascadingDropdown" data-url="/Year" data-select-message="Select a year...">
  </select>
  <select id="Make" name="Make" class="cascadingDropdown" data-url="/Make" data-parent-fields="Year" data-select-message="Select a make...">
  </select>
  <select id="Model" name="Model" class="cascadingDropdown" data-url="/Model" data-parent-fields="Year,Make" data-select-message="Select a model...">
  </select>
</form>

3. Initialize

CascadingDropdown.init({
	selector:'.cascadingDropdown',
  	source: function(url,parms,callback) {
    		//A json array containing Text and Value properties for each option must be passed into the callback.
    		callback([{"Text":"First Value","Value":"1"},{"Text":"Second Value","Value":"2"}]);
  	}
});

License

The code is available under the MIT License.

cascading-dropdown's People

Contributors

bertwagner avatar

Stargazers

 avatar

Watchers

 avatar

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.