function checkinput() { var o={}; var v = ""; $('input').each(function(i) { if(!(o[$(this).val()])){ o[$(this).val()] = true; }else{ $(this).css('border-color','red'); v = $(this).val(); } }) $('input').each(function(i) { if($(this).val()==v){ $(this).css('border-color','red'); } }) }