Try this:
$('.class').chosen().change(function () {
var code = $(this).val();
var maxOptions = code == 1 ? 5 : 3;
$(".class_attr").chosen('destroy').chosen({ max_selected_options: maxOptions });
});
It looks like you can't change any options after it's been initalised so it has to be destroyed before being created once more.
[EDIT]
You can access Chosen instance through $(".class_attr").data('chosen')
.
Then you can update options directly on the instance :
$('.class_attr').data('chosen').max_selected_options = 2;
$('.class_attr').trigger("chosen:updated");