Results 1 to 2 of 2

Thread: Add an event to a textbox at runtime

  1. #1
    Join Date
    Aug 2011

    Add an event to a textbox at runtime


    I am working on a site in which I must make a text box that cannot allow numbers to be entered. My only problem is that I cannot insert an onKeyPress or onKeyDown event into the input tag itself, I must do this elsewhere in my code.

    Any help with this would be appreciated


  2. #2
    Join Date
    Aug 2011
    If this is any help here is what I have so far, this page does exactly what I want it to do, the onKeyPress event must be somewhere in the script though

    <SCRIPT language=Javascript>

    function isNumberKey(evt)

    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

    return true;


    <p>Numbers Only</p>
    <INPUT name="box1" onkeypress="return isNumberKey(event)" type="text">


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles