JqueryJquery plugins   PortFolioSenamion's PortFolio HomeHome page corner A jquery blog

Senamion.com


Senamion:

Categorie:

jDoubleSelect: jQuery plugin transform one select with optgroups into two selects

10 marzo 2010 by Giovanni

jDoubleSelect is a jQuery plugin to transform one select with optgroups into two selects, the first one with all groups and the second updated with the options of the group selected.

The screenshot:
jDoubleSelect screenshot

See the plugin jDoubleSelect page!

In Jquery | 14 Comments »

14 Comments a “jDoubleSelect: jQuery plugin transform one select with optgroups into two selects”

  1. Giovanni scrive:

    New version 0.1 faster!

  2. rob scrive:

    Great – but when I add a second select to my form, doubleselect takes control of that too and I get two empty dropdown boxes

    one
    two

  3. Giovanni scrive:

    You must attach jDoubleSelect only to your select, eg:

    $("[name=nameOfSelect]").jDoubleSelect();
    
  4. rob scrive:

    Thanks – after a bit of reading about jquery I got it working by replacing select with #zone where zone is the ID of the select element.

  5. Giovanni scrive:

    With $(”[name=nameOfSelect]“)… you select the field with name nameOfSelect.

  6. Giovanni scrive:

    New version 0.2 with new option {text: ‘text’} for text between 2 selects.

  7. Izikd scrive:

    I wouldn’t work if name is something like “data[User][Password]“.
    Especially when using CakePHP.

    To make it work properly changed the line:

    var	name1 = $(this).attr("name") + "_jDS";
    

    TO:

    var	name1 = $(this).attr("id") + "_jDS";
    
  8. Izikd scrive:

    When first select selected, the overall value wouldn’t change to the first value in the second select.

    FIND:

    el.next().next().after(""+el.find("optgroup[label="+$(this).val()+"]").html()+"");
    

    AFTER ADD:

    el.val($("#"+name2).val());
    
  9. Giovanni scrive:

    Thank you very much, but second solution is very very slow in firefox, I tested also:

    $("#"+name2).trigger("change");
    

    But is slow too, I must think a solution…

  10. Izikd scrive:

    For some reason the problem is on setting value on `el`.
    For example: `el.val(100)` (even if it’s just a number!)
    It makes the slowness.

    With original version 0.3, on Demo2 you have performance issue when selecting 2nd select.

    This seems like fixing the issue:
    FIND:

    el.val($(this).val());
    

    REPLACE WITH:

    el.attr("value", $(this).val());
    

    FIND:

    el.next().next().after(""+el.find("optgroup[label="+$(this).val()+"]").html()+"");
    

    AFTER ADD:

    $("#"+name2).trigger("change");
    

    Please insure that using `attr(”value”, value)` gives the same result as `val(value)`.

  11. Giovanni scrive:

    I don’t understand why, but with el.attr(”value”, $(this).val()); is fast! I think is a jQuery problem!
    Thank you very much Izikd!!!

  12. Izikd scrive:

    Glad to help ;)

  13. N8 scrive:

    Looks like an interesting plug-in. Does it support multiple selects? If it can be made to work with multiple selects, I think it would be a good fit for a current project.

  14. Giovanni scrive:

    For multiselect you can use this plugin!

Write a comment