jqueryformsdrop-down-menuhtml-selectoptions-menu

JQuery select options reordering after selection


I have a list of course names and I want my users to select their order of preference for each one. So say we have 3 courses, each course would have a drop-down list alongside it, with the options of '1st choice', '2nd choice', '3rd choice'.

Now here is the bit I'm stuck on. For arguments sake lets say the default is for the preference selection to be in the order they appear i.e. the top course's drop-down is set to '1st choice', middle course drop-down is set to '2nd choice' and the bottom course is set to '3rd choice'.

If the user changes the middle course to '1st choice', then the top course's drop-down should automatically change to '2nd choice' and the bottom course would remain as '3rd choice'.

If the user then changed the bottom course's drop-down to '1st choice', the middle course's drop-down would change to '3rd choice' and the top course's drop-down would remain as '2nd choice'.

Below is a diagram to help explain the flow. So the user changes which course is their '1st choice' each time.

Choices flow diagram

Here is the basic html before any JQuery

<ul>
    <li>
       <select>
          <option>1st Choice</option>
          <option>2nd Choice</option>
          <option>3rd Choice</option>
       </select>
        Course a</li>
    <li>
       <select>
          <option>1st Choice</option>
          <option>2nd Choice</option>
          <option>3rd Choice</option>
       </select>
        Course b</li>
    <li>
       <select>
          <option>1st Choice</option>
          <option>2nd Choice</option>
          <option>3rd Choice</option>
       </select>Course c</li>
</ul>

Solution

  • I've found a plugin called selectPool that does what I need:
    https://github.com/meritec/jquery-select-pool

    I've put together a demo, including a fix as the original plugin didn't work. I changed $this from this.filter("select"); to $('select',this);
    http://jsfiddle.net/XuZa2/