I found a solution to my problem by extending the aforementioned combobox control. XGreen's first suggestion using
$('.selector').live("change", ...)
didn't work because the change event is not triggered when modifying a select using .val() (at least not in jquery 1.4.4. Upgrading is not possible right now)
Hence, I added this code to the combobox's construction:
select.observe_field(1, function() {
var selected = select.children(":selected");
var value = selected.val() ? selected.text() : "";
input.val(value);
});
Where observe_field is some not soo efficient function found on the web:
jQuery.fn.observe_field = function(frequency, callback) {
return this.each(function(){
var element = $(this);
var prev = element.val();
var chk = function() {
var val = element.val();
if(prev != val){
prev = val;
element.map(callback); // invokes the callback on the element
}
};
chk();
frequency = frequency * 1000; // translate to milliseconds
var ti = setInterval(chk, frequency);
// reset counter after user interaction
element.bind('keyup', function() {
ti && clearInterval(ti);
ti = setInterval(chk, frequency);
});
});
};
Better solutions are still very welcome!