Web Analytics Made Easy -
StatCounter Hard One: capturing keyevent with exceptions with multiple forms - CodingForum


No announcement yet.

Hard One: capturing keyevent with exceptions with multiple forms

  • Filter
  • Time
  • Show
Clear All
new posts

  • Hard One: capturing keyevent with exceptions with multiple forms

    I have a 'hard' question..I think...here it is..

    I am capturing the "enter" keystroke on a page with a few different forms...basically, I dont want people to be able to use the "enter" key to hit/submit things..they have to use buttons>>>EXCEPT when they are in a textarea/textbox area....

    now, this script needs to work across multiple pages (dynamic) with multiple "forms" on each page..

    so,,,,is there a way to "check for generic" forms (all of them) on a page, see if a 'textarea/textbox' is focused -- I guess that means its active..and if someone clicks enter at that point...it works...

    in other words, capturing the 'enter' keystroke under all condition except that noted above..here is what I have so far....I put it into a js file..

    function validateDelete(){
    if(confirm("You are about to DELETE database entries!\n Is this what you intend?")){
    return true;
    }else{return false}
    //this function captures the keyevent for enter and nullifies it
    netscape = "";
    ver = navigator.appVersion; len = ver.length;
    for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
    netscape = (ver.charAt(iln+1).toUpperCase() != "C");
    function keyDown(DnEvents) { // handles keypress
    // determines whether Netscape or Internet Explorer
    k = (netscape) ? DnEvents.which : window.event.keyCode;
    if (k == 13) { // enter key pressed
    if(count==0){alert('Enter Key is disabled, please click submit button')}
    return false;
    document.onkeydown = keyDown; // work together to analyze keystrokes
    if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);

  • #2
    uhmm...anyone here? -- hello..is this mic on?


    • #3
      One method

      In the past I needed to allow one to have a text field on the page that would be skipped in tab order, I created a global variable. And I then set this variable to the form control name with the onblur event.

      This allowed me to know what form field I was at last and effectivly skip to the next field.

      If you store the last form object in a global variable with the onfocus() event, I would think you could have the enter key press code check this global variable for its type and allow or disallow use based on that.

      If you cant read the object. Name all the text fields by prepending with "txt" ( example: txtSomeTextField ) and then save the name attribute into the global. Parse out the first 3 letters and look for 'txt'. That should work.

      -S. Bob