<script language="javascript">
function tusGir(tus){
    if (document.getElementById(nereye).value.length >= document.getElementById(nereye).getAttribute('maxlength'))
    {
        alert("En fazla "+ document.getElementById(nereye).getAttribute('maxlength') + " karakter girebilirsiniz.");
    }
    else
    {
        document.getElementById(nereye).value = document.getElementById(nereye).value + tus;
    }
}
</script></head>
<body>
<form action="" method="post" class="" name="numPad">
<table cellpadding="2" cellspacing="2" border="0" width="44">
<tr>
     <td colspan="3" align="center">
        <p align="right">Şifreniz
          <input id="quantity" type="text" name="quantity" size="10" maxlength="3" onfocus="nereye='quantity';"></td>
</tr>
<tr>
     <td colspan="3" align="center">
        <p align="right">Şifre2
          <input id="quantity1" type="text" name="quantity1" size="10" maxlength="3" onfocus="nereye='quantity1';"></td>
</tr>
<tr>
     <td><input type="button" value="  1  " onclick = "tusGir('1');"></td>
     <td><input type="Button" value="  2  "  onclick = "tusGir('2');"></td>
     <td><input type="Button" value="  3  "  onclick = "tusGir('3');"></td>
</tr>
<tr>
     <td><input type="Button" value="  4  "  onclick = "tusGir('4');"></td>
     <td><input type="Button" value="  5  "  onclick = "tusGir('5');"></td>
     <td><input type="Button" value="  6  "  onclick = "tusGir('6');"></td>
</tr>
<tr>
     <td><input type="Button" value="  7  "  onclick = "tusGir('7');"></td>
     <td><input type="Button" value="  8  "  onclick = "tusGir('8');"></td>
     <td><input type="Button" value="  9  "  onclick = "tusGir('9');"></td>
</tr>
<tr>
     <td colspan="3">
        <p align="center">
        <input type="button" value="       0         "  onclick = "tusGir('0');"></td>
</tr>
</table>
</form>
sanırım böyle daha sağlıklı olur.

inputlara bir id ve maxlength değeri vermeniz gerekiyor.

<input id="hede" type="text" name="abc" maxlength="10" onfocus="nereye='hede';" />

gibi.

gibi.