Enhance user experience by incorporating the functionality to navigate an HTML table, using the arrow keys,

My HTML table has input text in each td. I am attempting to develop a function that will enable arrow keys for navigating through the td's.

I aim to have the selected cell's value highlighted when any arrow key is clicked, similar to how the tab key works. Does anyone have suggestions on how this can be achieved? Thank you.

Sample Code: Here

Answer №1

To locate input individually, and assign a class to the Active input in the function rePosition(), you can use the following code:

$('#navigate tr td').find('input').removeClass('yourClassforText');
$('#navigate tr td').eq(active).find('input').addClass('yourClassforText');

// to select text inside input
$('#navigate tr td').eq(active).find('input').select();

Check out the old Demo Here

Update

Another issue mentioned by Op was to only remove selected text.
In order to achieve this, you must add a check on a keydown event like so:

var inp = String.fromCharCode(event.keyCode);
if (!(/[a-zA-Z0-9-_ ]/.test(inp) || event.keyCode == 96)){
    //if user is entering some text, neglect rePosition & reCalculate events
}

See the Updated Demo here

Update - 2:

Demo with thead added

Answer №2

Maximize your potential. Implement this code snippet in the adjustPosition method:

alert($('#navigate tr td').eq(active).find('input').val());

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

Create individual account pages with specific URLs in Next.js

I'm currently working on developing a website that will feature individual user pages showcasing their posts and additional information. I'm facing some difficulty in figuring out how to generate new links to access these user accounts. For insta ...

What is the best way to create fading text effects in an AngularJS application?

Running an AngularJS web application that showcases three words for 5 seconds each: Hello, World & Goodbye. The controller setup is as follows: self.currentIndex = 0; self.myTexts = ['Hello', 'World', 'Goodbye']; self.cu ...

Encountering an issue while trying to initiate a fresh React Native Project

As I work through the setup steps outlined in the React Native Documentation on my M1 MacBook Pro, I encounter a stumbling block. Despite successfully running React projects and Expo projects on this machine before, I hit a snag when trying to create a new ...

HELP! Imagemaps are being ruined by overlapping DIVs!

I encountered a minor issue. In summary, I have a container div that displays rotating images and image maps with clickable links within each image setup like a gallery with built-in navigation. Recently, I was tasked with adding simple animations to the i ...

Using jQuery, you can easily deactivate the form submission button for both text and checkbox input fields

I have a form consisting of three input fields (type=text, multiple checkboxes, and a disabled submit button). I need the submit button to become enabled only when the user has filled out all three text inputs and selected at least one checkbox. While I f ...

"Initially, the input state does not establish a binding for onChange event upon

A state named account_type has been declared, and an onChange event has been created to change the state's value when the div is clicked. <div className="price-plan" value="star" onClick={() => this.setPlan("star") ...

Experiencing an issue while rendering due to the presence of display: table-cell;

I am currently in the process of developing a website. The HTML Header section is structured as follows: <div id="page"> <header> <a href="#" class="redsquare">&nbsp;</a> <div class="head-wrapper"> ...

A JavaScript async function with a nested call inside

Below is my node function for the API server: router.post('/find', async (req, res) => { try { const firewalls = []; let count = 0; const devices = await Device.find({ ...req.body }); devices.forEach(async (item) => { ...

Adjust dropdown options based on cursor placement within textarea

I have a textarea and a dropdown. Whenever a user selects an option from the dropdown menu, it should be inserted into the text area. However, I am facing a bug where the selected value is being inserted at the end of the text instead of at the current cur ...

Tips for aligning a div vertically at the bottom with overflow auto

I have some HTML code that looks like this: <div class="ex"> <div class="ex0"> <div class="ex1"> <div class="ex2"> .... </div> <div class="ex3"> .... </div> </div> </div> </div> ex0 is pos ...

What steps can I take to ensure that when the user clicks the logout button, they are redirected to the home component?

Struggling to find a way to direct the user back to the Home component after logging out. The API functionality has been tested and is working properly. I'm unsure how to properly implement the logout method in the current context to allow for succes ...

Difficulty maintaining root properties in AngularJS custom directive

I recently created a custom sidebar directive, and although it is loading correctly in the designated area, I am encountering issues with the dropdown functionality of certain tags. The desired behavior is for these tags to display their inner elements whe ...

Tips for utilizing CSS Pseudo-classes with ASP.NET LinkButtons

Is there a way to add a pseudo class from an external CSS file to a link button on a web page? The CSS styles are defined in a separate CSS file that is referenced in the ASPX page. I want to apply these pseudo classes to my link button. How can this be ac ...

Custom querying with NodeJS and MongoDB

Currently, I am running a NodeJS server with express and handling a get method at '/api/jobs/'. This method involves retrieving querystring parameters from the URL and using them to query the MongoDB database for job information. For example, th ...

Is there a way to have Javascript (specifically node.js) wait until the form has been submitted before proceeding?

I have a unique request for the program/script I am working on. After the console logs '3', I would like the program to pause/wait until the user clicks "Finished!" (and data is downloaded from the form above). Clicking the button should restart ...

PlateJS: Transforming HTML into data

Trying to implement a functionality where clicking on a button retrieves an HTML string. The objective is to have this rich text editor within React-Hook-Form, and upon form submission, the value will be saved as HTML for database storage. Below is the pr ...

One way to specify a callback is by embedding a function within another function. This can be accomplished in JavaScript ES

A.file function Carousel(){ ~~~~~~ code ~~~~~~ this.add = function(data){ do_something() self.addCallback.call(this, arguments) }; this.remove = function(data){ do_something() this.removeCallback.call(this, arguments) }; ...

Is there a way in JQuery to apply the CSS of one element to another selected element?

I'm curious if there is a JQuery function available that can be used to transfer the exact CSS styles from one element to another. I want all the CSS properties to be applied without any additional inheritance. For example: <div id="d1"> &l ...

Using JavaScript to eliminate a folder from numerous image src attributes

I am facing a challenge on my website where I have multiple gallery categories that initially display smaller thumbnails. However, once the screen width goes below 1200px, I want to switch to displaying full-size images. The current setup of image display ...

Reordering Bootstrap 4.1 columns for improved visibility on smaller screens

I'm having trouble adjusting the column order for small screen resolutions in Bootstrap 4.1. I've added the order prefix but nothing seems to be changing. Here is a snippet of my HTML code. Can anyone offer assistance? <div class="container-f ...