Created
November 26, 2012 09:25
-
-
Save gockxml/4147363 to your computer and use it in GitHub Desktop.
bind_select
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment