javascript input allowing only numbers
<p>i use this code and it works</p>

<pre><code>&lt;HTML&gt;
  &lt;HEAD&gt;
    &lt;SCRIPT language=Javascript&gt;
       &lt;!--
       function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode != 46 &amp;&amp; charCode &gt; 31 
            &amp;&amp; (charCode &lt; 48 || charCode &gt; 57))
             return false;

          return true;
       }
       //--&gt;
    &lt;/SCRIPT&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;INPUT id="txtChar" onkeypress="return isNumberKey(event)" 
           type="text" name="txtChar"&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</code></pre>

<p>but I do not have access to the html, and have only javascript<br></p>

<pre><code>document.getElementById("txtChar").addEventListener("keypress", &lt;&lt;your code&gt;&gt;, false);
</code></pre>

<p>what should be in place <code>&lt;&lt;your code&gt;&gt;</code>? </p>

<p>p.s. found another bug with this component:<br>
when you copy-paste(ctrl-v  or right click-paste) it does not work<br>
can someone know how to resolve it</p>
