www.webdeveloper.com
Results 1 to 2 of 2

Thread: Add an event to a textbox at runtime

Hybrid View

  1. #1
    Join Date
    Aug 2011
    Posts
    2

    Add an event to a textbox at runtime

    Hello,

    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

    Thanks,

  2. #2
    Join Date
    Aug 2011
    Posts
    2
    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



    <HTML>
    <HEAD>
    <SCRIPT language=Javascript>
    <!--


    function isNumberKey(evt)
    {

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

    return true;
    }





    //-->
    </SCRIPT>
    </HEAD>
    <BODY>

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


    </BODY>
    </HTML>

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