title: Javascript checking if username already exists(duplicate)
body: <p>I created a function that checks if the username already exists in the data list, but alert shows every time even if the username isn't in duplicate data list.</p>
  
  <pre><code>&lt;form onsubmit="return validation()"&gt;
      &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;Username:&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" id="user" name="user"&gt;&lt;/td&gt;
                  &lt;datalist id="list"&gt;
                      &lt;option value="Tilen"&gt;
                      &lt;option value="Marko"&gt;
                      &lt;option value="Teja"&gt;
                      &lt;option value="Tisa"&gt;
                      &lt;option value="Rok"&gt;
                      &lt;option value="Luka"&gt;
                      &lt;option value="Mojca"&gt;
                  &lt;/datalist&gt;
              &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  
  &lt;script&gt;
     function validation(){
         var user = document.getElementById("user");
              if(user.value.length &lt;= 20 &amp;&amp; user.value.length &gt;= 3){
              }
              else{
                  alert("Username has to be between 3-20 characters.")
               }
              //duplication data list
              var user = document.getElementById("user");
              if(user.value == list.value){
              }
              else{
                  alert("Username already exists.")
               }
     }
  &lt;/script&gt;
  </code></pre>