I have coded this where I add / delete classes when you select from the form. However if i choose as default select the 2nd select e.g.
You can export logic to a function and call this function on both change
and document.ready
event.
Also, if you have to add/remove
classes, try to use .toggleClass
$('#destination').change(function() {
updateUIState();
});
$(document).ready(function() {
updateUIState();
})
function updateUIState() {
var dest = $('#destination').find(":selected").text();
var isDest2 = dest === 'destination2';
$('#destin').toggleClass("has-warning", isDest2);
$('#destin').toggleClass("has-success", isDest2);
}