!https://travis-ci.org/tuupola/jquery_chained.png?branch=master!:https://travis-ci.org/tuupola/jquery_chained

h1. Chained Selects Plugin for jQuery

Chained is simple jQuery plugin for chained selects. You can choose from two different versions. Use jquery.chained.js if you do not want to make external queries for setting content of child selects. This version uses classnames of select options to decide content.

For more complex scenarios maintaining option tag classnames will get cumbersome. Also if you want to make queries against database use jquery.chained.remote.js instead. This version makes an external AJAJ query and uses the returned JSON to build child selects.

h2. Usage

Child selects are chained to parent select. All selects must have an id attribute. Child select options must have class names which match option values of parent select. When user selects something in parent select the options in child select are updated. Options which have matching classname with parents currently selected option will stay visible. Others are hidden.

First you must include jQuery and Chained in your code:

<pre><script src="jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery.chained.js" type="text/javascript" charset="utf-8"></script></pre>

Then lets assume you have the following HTML code:

<pre><select id="mark" name="mark">
  <option value="">--</option>
  <option value="bmw">BMW</option>
  <option value="audi">Audi</option>
</select>
<select id="series" name="series">
  <option value="">--</option>
  <option value="series-3" class="bmw">3 series</option>
  <option value="series-5" class="bmw">5 series</option>
  <option value="series-6" class="bmw">6 series</option>
  <option value="a3" class="audi">A3</option>
  <option value="a4" class="audi">A4</option>
  <option value="a5" class="audi">A5</option>
</select></pre>

You can now chain the series to mark. There are two different ways to do it. Choose yourself if you prefer more english like or shorter version. I prefer the shorter version.

<pre>$("#series").chained("#mark"); /* or $("#series").chainedTo("#mark"); */</pre>

h2. Advanced usage

For instructions on how to chain to multiple parents or how to build selects using JSON data, see the "project homepage":http://www.appelsiini.net/projects/chained.

h1. License

All code licensed under the "MIT License":http://www.opensource.org/licenses/mit-license.php. 

h1. Changelog

h3. 0.9.5

* Fix bug "#12":https://github.com/tuupola/jquery_chained/issues/12. Minified versions were missing trailing semicolon;
* Support for Travis and Grunt.

h3. 0.9.4

* Remote version now uses name attribute instead id when sending AJAJ query.

h3. 0.9.3

* Also support remote JSON to be array of arrays ("Marco Mariani":https://github.com/mmariani)

h3. 0.9.2

* Support for "jQuery plugin repository":http://plugins.jquery.com/

h3. 0.9.1

* Allow options to be preselected in HTML ("Nathan Gray":https://github.com/kolibrie)

h3. 0.9.0

* Initial release
