The Plugin you used in this example supports parameters like onComplete, onItemClick. hence refer to their documentation for more examples,
As a suggestion you can find "onItemClick" option as an alternative for onkeydown
Example Code Snippet:
$(".s1").dropdownchecklist( { forceMultiple: true
, onComplete: function(selector) {
var values = "";
for( i=0; i < selector.options.length; i++ ) {
if (selector.options[i].selected && (selector.options[i].value != "")) {
if ( values != "" ) values += ";";
values += selector.options[i].value;
}
}
alert( values );
}
, onItemClick: function(checkbox, selector){
var justChecked = checkbox.prop("checked");
var checkCount = (justChecked) ? 1 : -1;
for( i = 0; i < selector.options.length; i++ ){
if ( selector.options[i].selected ) checkCount += 1;
}
if ( checkCount > 3 ) {
alert( "Limit is 3" );
throw "too many";
}
}
});