In any case, to check if a similar value exists in the input field
EX: <input name="user1" value="bla1"> <input name="user2" value="bla2"> <input name="user3" value="bla1">
When submitting the form, verification will be checked, it will warn the user and add a class to the input with the same value.
More jQuery'ish
var inputs = $('input'); inputs.filter(function(i,el){ return inputs.not(this).filter(function() { return this.value === el.value; }).length !== 0; }).addClass('red');
Fiddle
Filters inputs based on a particular input with the same value
This is one way using a temporary object to track items of a specific value:
(function() { var inputs = {}; $('input').each(function() { if (inputs[this.value] !== undefined) { // a previous element with the same value exists // apply class to both elements $([this, inputs[this.value]]).addClass('same'); } inputs[this.value] = this; }); }());
.same { background-color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input name="user1" value="bla1"> <input name="user2" value="bla2"> <input name="user3" value="bla1"> <input name="user4" value="bla4"> <input name="user5" value="bla5">
- :
var dup = false; $.each("input", function(k, v){ if($(this).attr("name") == $(this).next("input").attr("name")){ dup = true; } if($this).is(":last")){ if($(this).attr("name") == $("input:first").attr("name")){ dup = true; } } });
Source: https://habr.com/ru/post/1584137/More articles:Объединение цепочки и назначение по ссылке в таблице данных. - rStrange NHibernate QueryOver syntax error - mysqlOrientDB shortestPath () using a specific @class edge? - javaRepresentation of a set in java and CQL - javaThe rfsrc () command in the randomForestSRC R package that does not use multicore functionality - parallel-processingCheck if it is possible to sort an array with a single swap of 2 elements - sortingПотребительский путь Kafka не должен заканчиваться/character - apache-kafkaSelecting rows or columns with data.table R? - selecthttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1584141/ddply-causes-a-fatal-error-in-rstudio-running-correlation-on-a-large-data-set-ways-to-optimize&usg=ALkJrhhLPrQizkSgviVrkt2_LrbVI2VvBgReact JS view not to re-render on setState () - javascriptAll Articles