title: prevent users from entering duplicate entries in text inputs in javascript
body: <p>I have a DOM in which I want to <strong>prevent users from entering duplicate entries</strong> in html text input. </p>
  
  <p>The above <strong>DOM</strong> is not in user's control. It is coming through php. </p>
  
  <p>At this moment, I am focussing only on <code>name="code[]".</code> </p>
  
  <p><strong>This is what I have tried</strong>:</p>
  
  <pre><code>$(function(){
  
  $('input[name^="code"]').change(function() {
  
      var $current = $(this);
  
      $('input[name^="code"]').each(function() {
          if ($(this).val() == $current.val())
          {
              alert('Duplicate code Found!');
          }
  
      });
    });
  });
  </code></pre>
  
  <p><strong>Problem Statement:</strong></p>
  
  <p>I am wondering what changes I should make in javascript code above so that when a duplicate code is entered, alert message "Duplicate code Found" should come up. </p>