Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.fn.subSelects = function(sels, vals) {
- function trueRefreshSelects(sels, vals) {var names = []; sels.each(function(){console.log(0);
- var $this = $(this);
- var prev = $this.prev();
- if (!$this.attr('name')) return undefined;
- if (!prev.hasClass('selectArea')) return undefined; console.log('1', $this.attr('name'));
- var m = prev.attr('id').match(/\d+$/); if (m.length === 0) return undefined; console.log('2', prev.attr('id'), m);
- var index = m[0];
- prev.remove();
- $this.find('option').remove();
- var b, d;
- do { d = document.getElementById("optionsDiv"+5); b = d != null; if (d) d.parentNode.removeChild(d); } while (b);console.log('3');
- var i, str = ''; for (i in vals) { if (!vals.hasOwnProperty(i)) continue; str+= '<option value="{index}">{value}</option>'.replace('{index}', i).replace('{value}', vals[i]) }
- $(str).appendTo($this);
- names.push($this.attr('name'));
- });
- refreshSelects(names);
- }
- function updateSelects(sels, vals) {
- var ctx = this.filter(':first');
- if (!ctx.is('select')) return undefined;
- var valKey = ctx.val();
- var vals = vals[valKey];
- if (typeof vals == 'undefined') throw 'unknown values for key {valKey}'.replace('{valKey}', valKey);
- trueRefreshSelects(sels, vals);
- }
- updateSelects.apply($(this), [$(sels), vals]);
- }
Advertisement
Add Comment
Please, Sign In to add comment