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.
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.
What I already know is that I need to check the .length on the textboxes, but the functionality afterwards is what is bugging me.
HTML
<asp:TextBox ID="txt1" runat="server" MaxLength="4"></asp:TextBox>
<asp:TextBox ID="txt2" runat="server" MaxLength="10"></asp:TextBox>
Javascript
<script src="jquery-1.4.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var $reg = $('#txt1');
var $acc = $('#txt2');
$reg.blur(function () {
if($reg.length < 4)
{
var $miss = 4 - parseFloat($reg.length);
}
});
$acc.blur(function () {
if($acc.length < 10)
{
var $miss = 10 - parseFloat($acc.length);
}
});
});
</script>