capturing from text area Shft+Enter, Control+Enter, Alt+Enter and browser issue.

Discussion in 'Javascript' started by HopfZ, Aug 28, 2006.

  1. HopfZ

    HopfZ Guest

    I tried to detect modifier+enter key press in textarea in Firefox,
    Opera and IE. The code is at the end. The result is
    Firefox 1.5 : shift+enter, ctrl+enter, alt+enter all detected.
    Opera 9 beta : shift+enter, ctrl+enter detected. alt+enter is
    reserved for the browser.
    Internet Explorer 6 : only shift+enter is detected.

    Why e.ctrlKey and e.altKey are not being detected in IE? Is it by
    design?

    <html>
    <head>
    <script type="text/javascript">

    function load(){
    var ta = document.getElementById('ta');
    ta.onkeypress = taKeyPress
    ta.focus();
    }
    function taKeyPress(e){
    var e = e || window.event;
    var hasMod = e.shiftKey || e.ctrlKey || e.altKey;
    var unicode = e.charCode || e.keyCode;
    if(hasMod && unicode==13 /*hasMode and enter key*/){
    alert('detected');
    return false;// cancel key press.
    }
    }

    </script>
    </head>

    <body onload="load()"><form>
    <textarea id="ta">textarea</textarea>
    </form></body>
    </html>
     
    HopfZ, Aug 28, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob Nicholson
    Replies:
    10
    Views:
    772
    Steven Cheng[MSFT]
    Aug 23, 2005
  2. Mark
    Replies:
    1
    Views:
    637
    Larry Barowski
    Jun 27, 2005
  3. hotadvice
    Replies:
    14
    Views:
    734
    hotadvice
    Oct 2, 2007
  4. Andy B.
    Replies:
    0
    Views:
    844
    Andy B.
    Apr 30, 2010
  5. leo
    Replies:
    1
    Views:
    312
    Bob Lehmann
    Dec 5, 2005
Loading...

Share This Page