rb = {} rb.check = function(elem) { var elem_id = $(elem).attr('id'); var errors = ""; $("form[id='"+$(elem).attr('id')+"'] input[accept='true']").each(function(){ $(this).removeClass('error'); if($(this).val().length < 1) { errors += $(this).attr('alt')+"\n"; $(this).addClass('error'); $(this).focus(function(){$(this).removeClass('error');}); } }); if(errors.length < 1) return true; alert("Please amend the following before continuing:\n"+errors); return false; }