views:

70

answers:

1

Hi,

I used a javascript FocusChange() in my aspx page. I have couple of controls and I need Hit enter key need to move next control based on tab index. It is working good in IE7 but not working in IE8... Please help me on this..

Thanks for your help in advance. The java script is given below.

function FocusChange() {
    if (window.event.keyCode == 13) {

         var formLength = document.form1.length; // Get number of elements in the form
         var src = window.event.srcElement; // Gets the field having focus
         var currentTabIndex = src.getAttribute('tabindex'); // Gets its tabindex

        // scroll through all form elements and set focus in field having next tabindex
         for (var i = 0; i < formLength; i++) {
           if (document.form1.elements[i].getAttribute('tabindex') == currentTabIndex + 1) {
             for (var j = i; j <= formLength; j++) {
                 if (document.form1.elements[j].disabled == false) {
                      document.form1.elements[j].focus();
                      event.returnValue = false;
                      event.cancel = true;
                      return;
                        }
                    }
                }
            }
        }
    }
A: 

I've got the same request as you, but solved it in a different manner, just replacing the Enter for Tab

    <script language="JavaScript">
    document.onkeydown = myOnkeydown;  
    function myOnkeydown()
    {        
        var key = window.event.keyCode;
        if (key == 13)  //13 is the keycode of the 'Enter' key
            {window.event.keyCode = 9; //9 is the code for the 'Tab' key. Essentially replacing the Enter with the Tab.
        }
    }
    </script>

Warning: Works in IE only.

Eduardo Molteni