Navigate to the following tabindex after submitting the form again

How can I enhance the user experience by allowing them to easily update generic names (name1, name2, name3) with more meaningful ones without being redirected back to the previous name? Look for the comment WHAT GOES HERE? below.

Example HTML layout:

<div class="name"><input type="text" id="nameinput1" value="name1" onchange="changeName(0)"></div>
<div class="name"><input type="text" id="nameinput2" value="name2" onchange="changeName(1)"></div>
<div class="name"><input type="text" id="nameinput3" value="name3" onchange="changeName(2)"></div>

Javascript code snippet:

var jsons = '[{' ;
var jsone = '"}]' ;
function changeName(index){
    var json = jsons;
    var name = document.getElementById("main").getElementsByTagName("input")[index].value;
    json += '"index":"'+index+'",'
    json += '"name":"'+name.replace(/\s/g,"")+jsone
    loadDoc(json,"ID","url",returnChangeName)
}       
function returnChangeName(xttp){
    window.location = "#";    //  WHAT GOES HERE?
}            
loadDoc(...){....}

Please note that only pure Javascript is used in this functionality, no jQuery has been incorporated.

Answer №1

To retrieve the next input in the callback function returnChangeName, simply pass the current index as a parameter. It is advisable to utilize the JSON.stringify method for converting objects to strings:

function updateName(index) {
    var name = document.getElementById("main").getElementsByTagName("input")[index].value;
    var json = [{
        index: index,
        name: name.replace(/\s/g, "")
    }];
    loadData(JSON.stringify(json), "ID", "url", returnChangeName(index));
}

function returnChangeName(index) {
    return function responseHandler(xttp) {
        var nextInput = document.getElementById("main").getElementsByTagName("input")[index + 1];
        if (nextInput) {
            // Implement desired action here
            // For instance, focus on the next input field
            nextInput.focus();
        }
    }
}

function loadData(jsonData, id, url, callback) {
    // Perform necessary operations
    callback({});
}

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

Accessing and playing audio files from Amazon S3 within Python code

I am attempting to directly read an audio file from S3 using Python. Initially, I record the audio with the following blob settings: blob = new Blob(audioChunks,{type: 'audio/wav'}); Then, I upload this file to S3 using Django: req=request.POST ...

Errors can occur in React/Axios when API calls are served over HTTP instead of HTTPS

I'm currently utilizing an API to retrieve movie data by making use of axios within my React application. This functionality is operating as intended in my local environment; however, when I deployed the app to github pages, it ceased to function prop ...

Using Node.js and JQuery to execute a PHP script

I have integrated the tty.js project terminal into my web application (https://github.com/chjj/tty.js/). I am attempting to add a jQuery treeview to the homepage to display root folders. The jQuery treeview works fine when tested on Apache, but I encounter ...

Struggling to send Python JSON object using Django AJAX

Having some trouble implementing the ajax plugin for Django from https://github.com/yceruto/django-ajax. I've managed to use ajaxPost successfully, but I'm facing issues with ajaxGet. Within views.py, all the data is being printed correctly in P ...

Image not located: 404 error in JavaScript

I am currently working with JavaScript and have encountered an issue. I have an array of objects that contain various data such as id, title, price, and image. I need to retrieve this data from the array in order to display it. While I am able to successfu ...

React: How to retrieve values from a dynamic dropdown menu

For my React project, I have integrated ant design components. Currently, I am working on adding dynamic select functionality and retrieving the selected values. I have successfully implemented dynamic dropdown selection. However, I am facing an issue wi ...

What is the best way to limit the number of items shown in a cart dropdown using JavaScript

I have a shopping cart feature added to my ecommerce web app. Within the header, there is an icon of a cart. When clicked, a dropdown appears showing the items added to the cart. However, if I have 10 items in the cart, the dropdown becomes too lengthy to ...

Discovering how to locate a div element in one component from a separate component using Vue.js

Imagine having multiple Vue.js components in one project. <loginFields></loginFields> <submitButton></submitButton> Now, when the submitButton (which is a div with a unique id) is clicked, I want to initiate a method that checks t ...

Having trouble setting up Typescript in VisualStudio 2015 due to the error message "exports is not defined"? Need guidance on the correct setup?

I am new to TypeScript and I am currently learning about exports and imports in TypeScript However, as I started working on it, I encountered an error with exports Object.defineProperty(exports, "__esModule", { value: true }); The error message I receiv ...

How to italicize a portion of output using JavaScript

There are numerous inquiries on the internet and on this site regarding how to make italic fonts, however, none specifically address how to italicize only a section of a string. In my scenario, I have a form where I input the book title, author's nam ...

Guide on determining the total count based on a specific condition with the help of jQuery

Using AJAX, I have successfully retrieved all status values such as Active, ACTIVE_DRAFT, and Pending. However, I only want to select the statuses that are equal to ACTIVE. To do this, I am using an if condition which is working fine. After filtering by st ...

displaying a div as a pop-up within an ASP.NET MVC 4 web application

One aspect of my asp.net MVC 4 application involves a partial view structured like so: <form class="qty-add" action="#" method="POST"> <label>Qty:</label> <div class="inp-controller"> <a href="#" c ...

Unable to retrieve a state property within a Vue template

Embarking on my Vue journey, I've been immersing myself in online videos to grasp the essence of this framework. One intriguing observation that has piqued my curiosity is the difference in behavior when I switch from a template to a render function i ...

How should elements be properly inserted into injected HTML code?

We are currently phasing out our custom forms in React on the website, and transitioning to Microsoft Dynamics 365 generated forms. These new forms are injected through a React placeholder component created by a script that loads the js bundle and inserts ...

Excessive recursion in MooTools causing issues with Google Maps integration

Hello, I'm currently facing an issue with my WordPress plugin. Whenever Mootools is included, Google Maps are not displaying due to "too much recursion" error. Here is a snippet of the code for reference: Any suggestions or workarounds for this incon ...

The event bus I'm using isn't functioning properly within the axios interceptor, yet it operates smoothly in all my Vue components

Currently, I am utilizing VueJs and mitt for the eventBus. The mitt is globally loaded and functioning correctly as shown below: main.js const emitter = mitt(); const app = createApp(App) app.config.globalProperties.emitter = emitter I am able to call t ...

Migration unsuccessful due to incompatible peer dependencies detected - Updating Angular to Version 12 was not successful

Currently in the process of upgrading my Angular v11 apps to Angular v12. Encountering an error while attempting to upgrade Angular packages: ng update @angular/core@12 @angular/cli@12 Error: Migration failed due to incompatible peer dependencies The pa ...

Ensuring the correct range with HTML TextBoxFor

Is there a way to validate user input in a TextBoxFor to ensure it is less than a certain number at run-time? Here is the current code snippet for reference - <div class="col-md-3 input-group"> <span class="input-group-addon ...

When working with Nuxt 3, the referrer header may sometimes return as undefined

I am looking to capture the referrer header and store it in a cookie so that I can later use it to populate an axios request during the user's journey on my website. In my app.vue, I currently have the following code snippet: const headers = useReque ...

Distinguishing Between server.listen() and app.listen() in Google Apple Engine

I am currently working on a NodeJS + Express application. While running it locally, I have the following code: const port = 3001; server.listen(port, () => { console.log(`App listening on port ${port}`); }); However, when deploying to GAE, I switch ...