I have this:
function addSelectOnChange(select_id,selected_cb) {
$(select_id).live("change",function() {
var value = $(select_id + " option:selected").val();
if(value) {
selected_cb(value);
}
});
}
Is there another way of telling jQuery that I want to get the selected option, than by concatenating the selector?
Have a look at the examples of
.val(). You can do:Better in this case:
or even (see HTMLSelectElement):