Javascript algorithm adding numbers to textbox
<p>I have 2 textboxes. One which at all times should contain 4 digits when you leave it. One which at all times should contain 10 digits when you leave it.</p>

<p>I need a javascript which on blur from one of the textboxes should trigger an algorithm which shall calculate the amount of characters in the just blured textbox and if the textbox does not contain the specific amount of digits, it shall add x amount of 0 (zeroes) in front of the digits untill the textbox contains the specific amount of digits in it.</p>

<p>What I already know is that I need to check the .length on the textboxes, but the functionality afterwards is what is bugging me.</p>

<p><strong>HTML</strong></p>

<pre><code>&lt;asp:TextBox ID="txt1" runat="server" MaxLength="4"&gt;&lt;/asp:TextBox&gt;
&lt;asp:TextBox ID="txt2" runat="server" MaxLength="10"&gt;&lt;/asp:TextBox&gt;
</code></pre>

<p><strong>Javascript</strong></p>

<pre><code>&lt;script src="jquery-1.4.4.min.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
$(document).ready(function () {
    var $reg = $('#txt1');
    var $acc = $('#txt2');

    $reg.blur(function () {
        if($reg.length &lt; 4)
        {
            var $miss = 4 - parseFloat($reg.length);
        }
    });

    $acc.blur(function () {
        if($acc.length &lt; 10)
        {
            var $miss = 10 - parseFloat($acc.length);
        }
    });
});
&lt;/script&gt;
</code></pre>
