Checking password match while typing
<p>I have a registration form with "password" and "confirm password" input fields. I want to check if the "confirm password" matches the "password" while the user is typing it and give the appropriate message. So I tried to do this:</p>

<p>This is the HTML:</p>

<pre><code>&lt;div class="td"&gt;
    &lt;input type="password" id="txtNewPassword" /&gt;
&lt;/div&gt;
&lt;div class="td"&gt;
    &lt;input type="password" id="txtConfirmPassword" onChange="checkPasswordMatch();" /&gt;
&lt;/div&gt;
    &lt;div class="registrationFormAlert" id="divCheckPasswordMatch"&gt;
&lt;/div&gt;
</code></pre>

<p>And this is the checkPasswordMatch() function:</p>

<pre><code>function checkPasswordMatch() {
    var password = $("#txtNewPassword").val();
    var confirmPassword = $("#txtConfirmPassword").val();

    if (password != confirmPassword)
        $("#divCheckPasswordMatch").html("Passwords do not match!");
    else
        $("#divCheckPasswordMatch").html("Passwords match.");
}
</code></pre>

<p>That didn't validate while typing, only when user leaves the field.</p>

<p>I tried to use onKeyUp instead of onChange - also didn't work.</p>

<p>So how can it be done?</p>

<p>Thank you!</p>
