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
    349
    Thanks
    2
    Thanked 0 Times in 0 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 = "";
    count=0;
    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
    if(form
    // 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')}
    count++;
    return false;
    }
    }
    document.onkeydown = keyDown; // work together to analyze keystrokes
    if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
    //-->

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    349
    Thanks
    2
    Thanked 0 Times in 0 Posts
    uhmm...anyone here? -- hello..is this mic on?

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    USA, East Coast
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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


  •  

    Posting Permissions

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