title: Jquery making real-time input checking
body: <p>I am trying to write a script that validates user input. Like: letter length more than 5 or password and reentered-password match. But how can I get which input box in the form was clicked? I used </p>
  
  <pre><code>$(function() {
      $('#register input').keyup(function() {
          if ($('#username').val().length &lt; 5) {
              $('a.username').text("Please fill");
          } else {
              $('a.username').text("");
          }
  
          if ($('#password').val().length &lt; 5) {
              $('a.password').text("asdasd");
          } else {
              $('a.password').text("");
          }
  
      });
  });​
  </code></pre>
  
  <p>And </p>
  
  <p>
      
          
              New User
              User Name </p>
  
  <pre><code>        &lt;label for="password"&gt;Password&lt;/label&gt; &lt;input type="password" id="password" name="password"&gt;&lt;a class="password"&gt;&lt;/a&gt;
  
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>​</p>
  
  <p>When I click one of input elements, the code runs and it sees that second password input is also not full field and second <code>&lt;a&gt;</code> tag also fires. Should I use several <code>.keyup</code> functions for each element, or is there any method for getting which element clicked? Like </p>
  
  <pre><code>if (clicked == $("input#username") &amp;&amp; $('#username').val().length &lt; 5) {
      $('a.username').text("Please fill");
  
  } else {
      $('a.username').text("Please fill");
  
  }​
  </code></pre>
  
  <p>but this does not work. I think there should be something similar.</p>