Web Analytics Made Easy -
StatCounter keyCode for crtl+enter - CodingForum

Announcement

Collapse
No announcement yet.

keyCode for crtl+enter

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • keyCode for crtl+enter

    I'm trying to call a function from a specific keyCode entry using "onKeypress".

    now, the function i'm calling to, needs to be able to recognize "ctrl+enter". What I have so far is this:


    -------------------------------------------------------------------

    var reValidChars = /\d/;
    var reKeyboardChars = /[\x08\x0D]/;

    function ctrl_Enter(objEvent) {
    var iKeyCode, strKey;
    if (objEvent.keycode == "10") {
    if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey)) {
    window.alert('you hit ctrl plus enter!');
    }
    }
    }

    ------------------------------------------------------------------

    Any input will help!! I have been lothing over my computer screen for days now.

  • #2
    use onkeydown instead of onkeypress.

    var ctrl = event.ctrlKey;
    var code = event.keyCode;

    alert(ctr);
    alert(code);

    if (ctrl && code==13)
    alert("You press CTRL+Enter");

    I'm not sure that the keyCode for Enter is 13 (or 10?), change it appropriately if it was wrong. I did not test it.
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      Thanks! Much less code, It works great as-is.

      Comment

      Working...
      X