The auto-focus feature in the Hit Enter Javascript function works seamlessly in IE7, however, it faces compatibility issues in IE8

I have implemented a javascript function called FocusChange() in my aspx page to allow for easy navigation between controls by hitting the enter key. While it works perfectly fine in IE7, I am facing issues with IE8. Can anyone provide me with some guidance on this matter?

Thank you in advance for your assistance. Below is the snippet of the javascript code:

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

         var formLength = document.form1.length; 
         var src = window.event.srcElement; 
         var currentTabIndex = src.getAttribute('tabindex'); 

        // Loop through all form elements and set focus on field with 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;
                        }
                    }
                }
            }
        }
    }

Answer №1

I had a similar request as yours, but I approached it differently by simply substituting the Enter key with the Tab key.

<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 Enter with Tab.
    }
}
</script>

Note: This solution is only functional in Internet Explorer.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to implement a watch on $validator.errors in Vue.js using the Vee Validation plugin?

My intention was to implement a watch on $validator.errors, so that any error that arises gets logged, To achieve this, I checked the length of errors and stored self.errors.all() in a variable, However, I'm curious if it's possible to directly ...

Verify if there is a cookie available; then execute the load() function. If the cookie matches, it is necessary to

$(document).ready(function() { var hrefs = { "en": ["includes/test1.html", "includes/test2.html"], "es": ["includes/test3.html", "includes/test4.html"] } $(function() { var cookie = Cookies.get('langCookie'); if (cookie) { ...

Tips for adding styles to the first and last elements of a printed page

I have created a dummy code example that generates multiple paragraph elements with some text in it. However, I need to add borders to the first and last elements to enhance the design. Here is the code snippet: <!doctype html> <html> <he ...

Combine consecutive <p> tags within a <div> container

Can you group all adjacent <p> elements together within a <div> element? For example, assuming the following structure: <div class="content"> <p>one</p> <p>two</p> <h2> not p</h2> <p>thr ...

Arranging a JSON data structure (varied sequence in Firefox)

Looking to organize a JSON Object based on the key - Chrome maintains the order I need, but Firefox does not. Below is an example of my JSON object: { "media": { "1387185503": { "id_profil": "7256", "photo_profil": "http://www.mupiz.com ...

Having trouble with returning an object from a function in ASP.NET MVC

i am feeling a bit lost with my code: Here is a snippet from my controller: public void logIn(string username, string password) { User user = new User(); user.retrieveUser(username , password); if (user.user ...

Ways to embed a series of images within a stationary container

I have a fixed lateral div (like a menu bar) and I am exploring options for displaying images in a table-like format within the div. The challenge is that these images are dynamically generated. Specifically, I need to place 10 images in the div. While I ...

AngularJS: The best practices for passing $scope variables to functions

Exploring the TodoMVC application has been a great way for me to enhance my skills with AngularJS. While delving into the index.html file, I stumbled upon lines 14-16 which contain the following code: <form id="todo-form" ng-submit="addTodo()"> ...

Utilize the PHP variable HTTP_USER_AGENT to identify and analyze the user's browser

As I embark on creating a webpage, my goal is to have it display different content based on the user's browser. The SERVER [HTTP_USER_AGENT] variable initially seemed promising for this purpose, but upon inspecting the page in Chrome, I encountered: ...

Randomize checkbox selection using Javascript and Bootstrap

I'm in a bit of a bind with my webpage and could really use some help to figure it out. Here's the issue: On my website, there's a table of players. Each player has two checkboxes on their line: one to show if they are active (checked), and ...

Looking for a way to identify when a DOM element is resized as a result of web fonts loading asynchronously?

Within this div element lies text styled with a custom font via CSS's @font-face attribute. The issue arises when the font hasn't loaded yet, causing a delay in updating the font style of the text within the div. As a result, taking measurements ...

Jquery script that utilizes the Steam WebAPI to return data

I'm encountering an issue with a script I found on github. I added value.appid myself, thinking it was logical, but I believe that data.response.games contains values for all my games. How can I either print or view what is defined? I would like to ...

Using AngularJS: Verify the presence of a key/value pair in an object and create an array of objects

My current service method retrieves income data from different projects and creates a new array of objects. I am seeking assistance to sort this array by year and trimester in order to simplify looping through it using ng-repeat in the view. The data stru ...

Tips for effectively formatting JSON data

Looking to optimize my JSON data formatting, specifically targeting two different keys within an object. Both keys are strings. I've created a fiddle showcasing the JSON structure: fiddle var json = [ { "Id": 1, "ReportId": 1, "ReportNa ...

Guide on creating my inaugural HTML embeddable widget?

A client recently requested me to create a JavaScript (MooTools)/HTML/CSS/PHP based game as a deployable widget. This will be my first time developing a widget, so I am seeking advice and insights to help me navigate any potential challenges from experie ...

"Can you guide me on how to display a React component in a

I have a function that loops through some promises and updates the state like this: }).then((future_data) => { this.setState({future_data: future_data}); console.log(this.state.future_data, 'tsf'); }); This outputs an array o ...

AngularJS displays true for $scope.form.$submitted

I am working on a multi-step form and I am facing an issue with controlling user submissions. I need to validate each step before proceeding to the next one. Even though I am implementing validation checks and moving to the next step accordingly, the $scop ...

Display scrollable content at the bottom

I am currently working on creating a chat application using JavaScript (AngularJS without jQuery) and I am wondering if it is possible to have a scrollable div load to the bottom automatically. While I am familiar with the scrollTo JS property, I do not f ...

What is the best method for extracting JSON objects from an HTML page after executing a JS script with PhantomJS, and then transferring them to Java code?

I have been utilizing a JavaScript script code as mentioned in this specific answer. However, my goal is to avoid saving the resulting HTML page into an HTML file. Instead, I am looking to extract a JSON object from the <div class="rg_meta"> and tran ...

Adjust the border color of an image when a radio button option is selected

I manage an online shop using WooCommerce that includes a filter for selecting product colors. The available color options are black, blue, and white. When customers choose a color option, only the products in that specific color will be displayed automati ...