Skip to content

Instantly share code, notes, and snippets.

@gockxml
Created November 26, 2012 09:25
Show Gist options
  • Select an option

  • Save gockxml/4147363 to your computer and use it in GitHub Desktop.

Select an option

Save gockxml/4147363 to your computer and use it in GitHub Desktop.

Revisions

  1. gockxml created this gist Nov 26, 2012.
    19 changes: 19 additions & 0 deletions bind_select.sj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    function bind_select(first, second, data){
    var change = function(evt){
    var first_elem = $(first)[0];
    var second_elem = $(second);
    second_elem.html("");
    second_elem = second_elem[0]
    values = data[first_elem.value]
    for (var i=0, len = values.length; i < len; i++){
    if (!(values[i] instanceof Array)){
    values[i] = [values[i]]
    }
    console.log(values[i])
    second_elem.options.add(new Option(values[i][0], values[i][1] || values[i][0]));
    }
    };

    $(document).on('change', first, change);
    //change()
    }