1/** 2* Chained Selects for jQuery 3* Copyright (C) 2008 Ziadin Givan www.CodeAssembly.com 4* 5* This program is free software: you can redistribute it and/or modify 6* it under the terms of the GNU General Public License as published by 7* the Free Software Foundation, either version 3 of the License, or 8* (at your option) any later version. 9* 10* This program is distributed in the hope that it will be useful, 11* but WITHOUT ANY WARRANTY; without even the implied warranty of 12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13* GNU General Public License for more details. 14* 15* You should have received a copy of the GNU General Public License 16* along with this program. If not, see http://www.gnu.org/licenses/ 17* 18* 19* settings = { usePost : true, before:function() {}, after: function() {}, default: null, parameters : { parameter1 : 'value1', parameter2 : 'value2'} } 20* if usePost is true, then the form will use POST to pass the parameters to the target, otherwise will use GET 21* "before" function is called before the ajax request and "after" function is called after the ajax request. 22* If defaultValue is not null then the specified option will be selected. 23* You can specify additional parameters to be sent to the the server in settings.parameters. 24* 25*/ 26;(function($) { 27 28jQuery.fn.chainSelect = function( target, url, settings ) 29{ 30 return this.each( function() 31 { 32 $(this).change( function( ) 33 { 34 settings = $.extend( 35 { 36 after : null, 37 before : null, 38 usePost : false, 39 defaultValue : null, 40 parameters : {'_id' : $(this).attr('id'), '_name' : $(this).attr('name')} 41 } , settings); 42 43 settings.parameters._value = $(this).val(); 44 45 if (settings.before != null) 46 { 47 settings.before( target ); 48 } 49 50 ajaxCallback = function(data, textStatus) 51 { 52 $(target).html(""); //clear old options 53 data = JSON.parse(data); //get json array 54 if ( data != null ) { 55 for (i = 0; i < data.length; i++) { 56 $(target).get(0).add(new Option(data[i].name, data[i].value), document.all ? i : null); 57 } 58 } else { 59 $(target).get(0).add(new Option('- select a country -', 0), document.all ? i : null); 60 } 61 62 if (settings.defaultValue != null) 63 { 64 $(target).val(settings.defaultValue);//select default value 65 } else 66 { 67 $("option:first", target).attr( "selected", "selected" );//select first option 68 } 69 70 if (settings.after != null) 71 { 72 settings.after(target); 73 } 74 75 $(target).change();//call next chain 76 }; 77 78 if (settings.usePost == true) 79 { 80 $.post( url, settings.parameters, ajaxCallback ); 81 } else 82 { 83 $.get( url, settings.parameters, ajaxCallback ); 84 } 85 }); 86 }); 87}; 88 89})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.