Im creating a simple message system with a mail inbox like UI. I have a select box that witll control a list of check box one for each message. It works fine but i need it with less code lines.
heres my code:
jQuery("#select_deselect").change(function(){
switch (jQuery(this).val()){
case 'unread':
jQuery("input[class=new_message]").each(function(){
jQuery(this).attr("checked", "checked");
});
jQuery("input[class=message]").each(function(){
jQuery(this).removeAttr("checked");
});
break;
case 'read':
jQuery("input[class=message]").each(function(){
jQuery(this).attr("checked", "checked");
});
jQuery("input[class=new_message]").each(function(){
jQuery(this).removeAttr("checked");
});
break;
case 'all':
jQuery("input[class=new_message]").each(function(){
jQuery(this).attr("checked", "checked");
});
jQuery("input[class=message]").each(function(){
jQuery(this).attr("checked", "checked");
});
break;
case 'none':
jQuery("input[class=new_message]").each(function(){
jQuery(this).removeAttr("checked");
});
jQuery("input[class=message]").each(function(){
jQuery(this).removeAttr("checked");
});
break;
default:
jQuery("input[class=new_message]").each(function(){
jQuery(this).removeAttr("checked");
});
jQuery("input[class=message]").each(function(){
jQuery(this).removeAttr("checked");
});
}
});
select_deselect is the id of my select box with options (null, all, read, unread, none).
new_message is the class asignesd to unread messages
message is the class asigned to read messages
i think a toggle() can doit but it will be the same lines.
Any idea to get this simply as posible