Coder Social home page Coder Social logo

jquery-cascading-dropdown's Introduction

jQuery Cascading Dropdown Plugin

A simple and lighweight jQuery plugin for cascading dropdowns.

View Demo

Installation

Include script after the jQuery library (unless you are packaging scripts somehow else):

<script type="text/javascript" src="/path/to/jquery-cascading-dropdown.js"></script>

Options

These options can be overridden for each individual select box.

usePost (boolean)

usePost: false

Tells the plugin to use POST when sending Ajax request. Otherwise GET will be used.

UseJson (boolean)

useJson: false

Tells the plugin to stringify (JSON.stringify) select box data before sending. Requires json2.js if you're planning to support older browsers.

textKey (string)

textKey: 'text'

The key to be used when parsing Ajax data for select box item text. (Required if url is set)

valueKey (string)

valueKey: 'value'

The key to be used when parsing Ajax data for select box item value. (Required if url is set)

selectBoxes

Array of select box objects

Select box properties

selector (string)
selector: '.selectbox1'

Selector for select box inside parent container. (Required)

url (string)
url: '/api/CompanyInfo/GetCountries'

Url to be used in Ajax request for fetching select box items. If this parameter is set, the textKey and valueKey parameters must also be set.

If this parameter is not set, the plugin will simply enable the select box.

requires (array)
requires: ['.selectbox1']

Array of select box selectors required to have value before fetching own list.

requireAll (boolean)
requireAll: true

If set to true, all select boxes defined in the requires array must have a value before this particular select box is enabled.

paramName (string)
paramName: 'countryId'

Required select box value parameter name used in Ajax request when fetching own list.

onChange (function)
onChange: function(value) { doSomething(value); }

Function to be executed when select box value is changed. Provides new select box value.

Server-side implementation

This plugin uses Ajax to execute a GET request for the list of option items to be inserted into the select boxes. So you'll need a web service that returns a JSON array of select box items.

Notice how there are two properties called textKey and valueKey. The values of these two properties are used to determine which property of the JSON array object should be used for the option text and which one should be used for the value. So if you have something like this in your select box object property:

textKey: 'country',
valueKey: 'countrycode'

Your JSON object should look something like this:

[
    {
        "country": "Malaysia",
        "countrycode": "60"
    },
    {
        "country": "Latvia",
        "countrycode": "371"
    }
]

jquery-cascading-dropdown's People

Contributors

dnasir avatar bcostea avatar dmdigital 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.