Use change event handler for select tag and in function, check if length of selected option is less than 2 remove disabled attribute and if is great than 2 add it to element.
document.getElementById("state").onchange = function(){
var length = this.querySelectorAll("option:checked").length;
document.querySelectorAll("#first, #second").forEach(function(ele){
ele.disabled = length < 2;
})
}
document.getElementById("state").onchange = function(){
var length = this.querySelectorAll("option:checked").length;
document.querySelectorAll("#first, #second").forEach(function(ele){
ele.disabled = length < 2;
})
}
one
two
Also you can do this work using jQuery with less code
$("#state").change(function(){
$("#first, #second").prop("disabled", $(":selected",this).length < 2);
});
$("#state").change(function(){
$("#first, #second").prop("disabled", $(":selected",this).length < 2);
});
one
two