Skip to content

Commit e433ac6

Browse files
committed
Solve Issue 2 preselectSecond does not work
1 parent 25fcdfc commit e433ac6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

jquery.doubleSelect.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@
4545
$second.val(value).change();
4646
};
4747

48+
/** Helper Function to remove childs from second */
4849
var removeValues = function() {
4950
$($secondid + " option").remove();
5051
};
5152

52-
$(this).change(function() {
53+
/** OnChange Handler */
54+
$(this).change(function() {
5355
removeValues();
5456
var $current = this.options[this.selectedIndex].value;
5557
if ($current !== '') {
@@ -78,7 +80,8 @@
7880
}
7981
);
8082
}
81-
o.appendTo($second);
83+
if (k === bestk) { o.html(k).attr("selected", "selected"); }
84+
o.appendTo($second);
8285
});
8386
}
8487
});
@@ -89,14 +92,18 @@
8992
});
9093

9194
return this.each(function() {
95+
96+
//remove all current items in select boxes
9297
$first.children().remove();
9398
$second.children().remove();
9499

100+
// Handle the empty option param
95101
if (options.emptyOption) {
96102
var oe = $("<option>").html(options.emptyValue).attr('value', options.emptyKey);
97103
oe.appendTo($first);
98104
}
99105

106+
// add all options to first select box
100107
$.each(values,
101108
function(k, v) {
102109
var of = $("<option>").html(k).attr('value', v.key);

0 commit comments

Comments
 (0)