Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts

    how to detect user click the "numeric" button?

    dear,

    i'm doing a calculator using Javascript, i want to detect user click on the numeric button from the keyboard. possible?
    when user click "1" i will set the "button"(HTML) number 1 was clicked?
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    document.onkeydown=checkKeys;
    if (navigator.appName == 'Netscape')
    document.captureEvents(Event.KEYDOWN);

    Code:
    function checkKeys(e) 
    {
    if (navigator.appName == 'Netscape') 
    theKey = e.which;
    else
    theKey = window.event.keyCode;
    if ((thekey>=48&&theKey<=57)&&(thekey>=96&&theKey<=105)) {
    key = String.fromCharCode(theKey);
    alert("You Pressed: "+key)
    }else{
    alert("This is not a number");
    }
    }
    You''ll need to play around with it a bit. Right now it filters out the numbers, but if you want them to be able to press * / - + = you'll need to add them in. You can also have them enter the text in a textbox, it would be much easier.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts
    this only work on Netscape? how about IE?
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++


  •  

    Posting Permissions

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