title: Using javascript to prevent duplicate values of dynamically generated input text boxes
body: <p>I have a 3 step (3 page) form. The first page that asks the user to check up to 5 of there favorite music genres. The second page dynamically displays the checked genres and then asks to rank them and the third page displays their music genre preference in order.</p>
  
  <p>My question is how can I use javascript to prevent duplicate values of dynamically generated input text boxes on the second page?</p>
  
  <p>I found this code (<a href="http://jsfiddle.net/zHJSF/" rel="nofollow">http://jsfiddle.net/zHJSF/</a>) that would work if my text box fields were set but the text box fields are being generated dynamically. It might be easier to tweak that code or do something different that involves a loop. I'm not sure.</p>
  
  <p>below is the code for the three pages:</p>
  
  <p>Page 1</p>
  
  <pre><code>&lt;form id="genre" name="genre" method="post" action="musicsell.php"&gt;
    &lt;input type="checkbox" name="genre[]" id="Rap" value="Rap"/&gt;Rap&lt;br /&gt;
    &lt;input type="checkbox" name="genre[]" id="HipHop" value="HipHop"/&gt;HipHop&lt;br /&gt;
    &lt;input type="checkbox" name="genre[]" id="RnB" value="RnB"/&gt;RnB&lt;br /&gt;
    &lt;input type="checkbox" name="genre[]" id="Rock" value="Rock"/&gt;Rock&lt;br /&gt;
    &lt;input type="checkbox" name="genre[]" id="Jazz"value="Jazz"/&gt;Jazz&lt;br /&gt;
  
    &lt;p&gt;
      &lt;input type="submit" value="Next"&gt;
      &lt;br /&gt;
    &lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Page 2</p>
  
  <pre><code>&lt;form id="form1" name="form1" method="post" action="musicresults.php"&gt;
  &lt;?php
  $name = $_POST['genre'];
  
  if(isset($_POST['genre'])) {
  foreach ($name as $genre){
  
  ?&gt;
  
  &lt;input type="number" required="required" id="&lt;?php echo $genre ?&gt;" name="music[&lt;?php echo $genre ?&gt;]" max="3" min="1" /&gt;&lt;?php echo $genre ?&gt;&lt;br /&gt; 
  
  &lt;?php
      }
  } 
  ?&gt;
  
  &lt;input type="submit" name="button" id="button" value="Submit" /&gt;&lt;/form&gt;
  </code></pre>
  
  <p>page 3</p>
  
  <pre><code>&lt;?php
  //Get the form results (which has been converted to an associative array) from the $_POST super global
  $musicgenres = $_POST['music'];
  
  //Sort the values by rank and keep the key associations.
  asort($musicgenres, SORT_NUMERIC );
  
  /*
  //Loop over the array in rank order to print out the values.
  foreach($musicgenres as $music =&gt; $rank)
  {
     echo "$music is your $rank choice";
     echo "&lt;br&gt;";
  }*/
  
  foreach($musicgenres as $music =&gt; $rank)
  {
     array_push($musicstring, $music); 
     echo "$music is your $rank choice";
     echo "&lt;br&gt;";
  }
  
  $musicstring = implode(", ", $musicgenres);
   echo $musicstring;
  ?&gt;
  </code></pre>