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 10 of 10

Thread: Event.KEYPRESS

  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Event.KEYPRESS

    I got this script

    function kH(e) {
    var pK = document.all? window.event.keyCode:e.which;
    return pK != 13;
    }
    document.onkeypress = kH;
    if (document.layers) document.captureEvents(Event.KEYPRESS);

    because I have a problem with a sign out button

    now no enter button works, is it possible to desable enter keypress only for one button ?

    thank you

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    I am sure there is a better solution, but it works:

    Code:
    <script>
     Allow=true; 
     function handleKeyPress(evt) {
      var nbr, chr;
      if (window.Event) nbr = evt.which;
      else nbr = event.keyCode;
      if(nbr==13 && !Allow){
        return false;
      }
     }
     function AllowSubmit(X){
       Allow=X;
     }
    
     document.onkeydown= handleKeyPress
    </script>
    
    
    <form name="FormName">
    <input type="button" name="ElementName" onclick="alert('eric1')" onfocus="AllowSubmit(false)" onblur="AllowSubmit(true)" value="No Enter">
    <input type="button" name="ASDF" onclick="alert('eric2')" value="Enter">
    </form>
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts
    but I don't want any ebent I want just that enter doesn't submit the form on a special button

    let say <button id="Logout" />

    thanks for helping

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts

    Did you try my code at all?

    ????
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #5
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes of course but I don't understand .... how can I get one button without enter, and other yes

    with a kind of code

    <input type="button" id="Login" value="Sign In" />


    <input type="button" id="Logout" onclick="noEnter('this.Id')" value="Sign out" />


    ??

    Login will work with enter
    and logout not

    thank you

  • #6
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You can not click enter on this button
    <input type="button" name="ElementName" onclick="alert('eric1')" onfocus="AllowSubmit(false)" onblur="AllowSubmit(true)" value="No Enter">

    You can click enter on this button
    <input type="button" name="ASDF" onclick="alert('eric2')" value="Enter">
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #7
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <?xml version="1.0" encoding="iso-8859-1"?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Enter | no Enter</title>
    <script>
    Allow=true;
    function handleKeyPress(evt) {
    var nbr, chr;
    if (window.Event) nbr = evt.which;
    else nbr = event.keyCode;
    if(nbr==13 && !Allow){
    return false;
    }
    }
    function AllowSubmit(X){
    Allow=X;
    }
    document.onkeydown= handleKeyPress
    </script>
    </head>
    <body>
    <form id="MainForm">
    <input type="button" id="ElementName" onclick="alert('eric1')" onfocus="AllowSubmit(false)" onblur="AllowSubmit(true)" value="No Enter" />
    <input type="button" id="ASDF" onclick="alert('eric2')" value="Enter" />
    </form>
    </body>
    </html>

    noramlly if I press enter I should get eric2 ....

    any way enter doesn't work it is the main thing

    thank you
    Last edited by angiras; 01-14-2004 at 04:47 PM.

  • #8
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    not working

    it doesn't work at all in this way I need the keypress for a script in dropdownlist , and with this code nothing works

    it must be possible to unallow keypress.enter only for one control ?

    in my case it is only for the logout button ...

    thank you for helping

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <input type="button" id="ASDF" onclick="alert('eric2')" value="Enter" onkeypress="return false;" onsubmit="alert();">


    note it was the wrong button I did it to I think lol, but only thing u should need to do is put 'onkeypress="return false;" ' in the rigth button.

  • #10
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <?xml version="1.0" encoding="iso-8859-1"?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Enter | no Enter</title>
    </head>
    <body>
    <form id="MainForm">
    <input type="button" id="ASDF" onkeypress="alert('Enter')" value="Enter" />
    <input type="button" id="ElementName" onclick="alert('No Enter')" onkeypress="return false;" value="No Enter" />
    </form>
    </body>
    </html>

    ok keypress doesn't work ..., is it right iin that way ?
    Last edited by angiras; 01-15-2004 at 11:36 AM.


  •  

    Posting Permissions

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