From dfaba4e0cc250a21abd97a30bb2f17af79d6469a Mon Sep 17 00:00:00 2001 From: janw Date: Fri, 21 Oct 2005 11:25:50 +0000 Subject: [PATCH] Automatic skip to next field if enter key pressed. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1652 594d385d-05f5-0310-b6e9-bd551577e9d8 --- html/include/focus.js | 64 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/html/include/focus.js b/html/include/focus.js index ba60e13d0..954d2f7af 100644 --- a/html/include/focus.js +++ b/html/include/focus.js @@ -14,17 +14,57 @@ for (iln = 0; iln < len; iln++){ } netscape= (ver.charAt(iln+1).toUpperCase() != "C"); -function keyDown(DnEvents) { +function keyPress(DnEvents) { // determines whether Netscape or Internet Explorer k = (netscape) ? DnEvents.which : window.event.keyCode; if (k == 13) { // enter key pressed - if (nextfield == 'login'){ - return true; // submit, we finished all fields - } else { // we're not done yet, send focus to next box - eval('document.mainform.' + nextfield + '.focus()'); - return false; - } - } + if(typeof(nextfield)!='undefined') { + if(nextfield == 'login') { + return true; // submit, we finished all fields + } else { // we're not done yet, send focus to next box + eval('document.mainform.' + nextfield + '.focus()'); + return false; + } + } else { + if(netscape) { + if(DnEvents.target.type == 'textarea') { + return true; + } else if (DnEvents.target.type != 'submit') { + // TAB + var thisfield = document.getElementById(DnEvents.target.id); + for (i = 0; i < document.forms[0].elements.length; i++) { + if(document.forms[0].elements[i].id==thisfield.id) { + // Last form element on page? + if(i!=document.forms[0].elements.length-1) { + document.forms[0].elements[i+1].focus(); + } + } + } + return false; + } else { + return true; + } + } else { + if(window.event.srcElement.type == 'textarea') { + return true; + } else if (window.event.srcElement.type != 'submit') { + // TAB + var thisfield = document.getElementById(window.event.srcElement.id); + for (i = 0; i < document.forms[0].elements.length; i++) { + if(document.forms[0].elements[i].id==thisfield.id) { + // Last form element on page? + if(i!=document.forms[0].elements.length-1) { + document.forms[0].elements[i+1].focus(); + } + } + } + return false; + } else { + return true; + } + } + } + } } function changeState(myField) { @@ -67,10 +107,12 @@ function changeTripleSelectState_2nd_neg(firstTriggerField, secondTriggerField, document.getElementById(myField).disabled= true; } } - -document.onkeydown= keyDown; // work together to analyze keystrokes +// work together to analyze keystrokes if (netscape){ - document.captureEvents(Event.KEYDOWN|Event.KEYUP); + document.captureEvents(Event.KEYPRESS); + document.onkeypress= keyPress; +} else { + document.onkeypress= keyPress; } function hide(element) { -- 2.30.2