Information provided in a login form does not carry over to a different page display

I'm currently facing a problem with my JavaScript code. I have constructed a login form and am attempting to transfer the data from the form to another page where it will be showcased in a table. Regrettably, the details are failing to appear on the subsequent page.

let tbody = document.querySelector("tbody");
const btnSend = document.getElementById("btnSend");
const nom = document.getElementById("nom");
const prenom = document.getElementById("prenom");
const age = document.getElementById("age");

function addData(nom, prenom, age) {
  let tr = document.createElement("tr");
  let tdNom = document.createElement("td");
  tdNom.textContent = nom;
  let tdPrenom = document.createElement("td");
  tdPrenom.textContent = prenom;
  let tdAge = document.createElement("td");
  tdAge.textContent = age;

  let btn = document.createElement("td");
  let suppBtn = document.createElement("button");
  suppBtn.classList.add("supp");
  suppBtn.textContent = "Supp";
  btn.appendChild(suppBtn);
  let modifBtn = document.createElement("button");
  modifBtn.classList.add("modif");
  modifBtn.textContent = "Modifier";
  btn.appendChild(modifBtn);
  
  tr.appendChild(tdNom);
  tr.appendChild(tdPrenom);
  tr.appendChild(tdAge);
  tr.appendChild(btn);
  tbody.appendChild(tr);
}
btnSend.addEventListener("click", ()=>{
addData(nom.value,prenom.value,age.value);
window.location.assign('index.html');
});
label {
    display: block;
    font-weight: bold;
    margin-bottom: 5px;
  }
  input[type="text"], input[type="number"] {
    display: block;
    width: 100%;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #ccc;
    margin-bottom: 20px;
    font-size: 16px;
  }
  button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    border-radius: 4px;
  }
  button:hover {
    background-color: #0069d9;
  }
<body>
    <h1>My Main Page</h1>
    <iframe src="index.html" width="100%" height="500px"></iframe>
    <label>Name:</label>
    <input type="text" id="nom"  placeholder="Your name here...">
    <label>Surname:</label>
    <input type="text" id="prenom"  placeholder="Your surname here...">
    <label>Age:</label>
    <input type="number" id="age"  placeholder="Your age here...">
    <button id="btnSend">Send</button>
  <script src="sc.js"></script>
</body>
the code of the page index.html

    <table>
        <thead>
            <th>Name</th>
            <th>Surname</th>
            <th>Age</th>
            <th>Actions</th>
        </thead>
        <tbody>
        </tbody>
    </table>
 

What might be causing the absence of data on the second page (index.html)? How can this issue be resolved?

Answer â„–1

tbody.appendChild(tr); /*<- make sure to include this element within your document, as it cannot be accessed from the login page since it belongs to another document */

Ensure that you send the login data to the appropriate page containing the table and handle the display function from there.

window.location.assign('index.html'); //<- Make sure to pass the field values to this function 

Attach your data to the URL in this format -> index.html?

var url = `index.html?Nom=${nom.value}&prenom=${prenom.value}&age=${age.value}`
window.location.assign(url)

Refer to this guide on how to pass data to other pages

In your index file, add the following code:

let params = new URLSearchParams(location.search);

let nom = params.get('nom');
let prenom  = params.get('prenom');
let age = params.get('age');

Alternatively, consider using localStorage which is recommended. Learn how to do it here

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

Update the input value following a successful action

How can I update the value of an input field after a successful ajax call? I have tried the following approach but it doesn't seem to be working. The result from the alert is 80000 Here is the HTML input code: <input class="form-control" type=" ...

Is it true that eliminating white spaces can enhance a website's loading speed?

I'm curious about something. Can removing white space actually make a website load faster? For instance, take a look at the following CSS snippet - body{ overflow-wrap:break-word; word-break:break-word; word-wrap:break-word } .hidden{ display:none } . ...

Tips for integrating TypeScript with Vue.js and Single File Components

After extensive searching online, I have struggled to find a straightforward and up-to-date example of setting up Vue.js with TypeScript. The typical tutorials out there either are outdated or rely on specific configurations that don't apply universal ...

Angular Search Version 2.0

I am facing an issue with my search functionality in Angular 2. When I type into the search box, the search method on the service is not triggered. I believe there might be a simple solution that I am missing. Any assistance would be greatly appreciated. ...

What is the most effective way to retrieve comments using Laravel Pagination without duplicates?

Lingering Issue: In the scenario where a user leaves a comment and subsequently opts to load more comments, they may encounter at least one duplicate comment. Root Cause: Using Laravel Pagination, the script leverages Axios to fetch the last 10 items. U ...

Create a sleek and dynamic navbar effect with Bootstrap 5 by easily hiding or showing it after scrolling

Is there a way to make the Bootstrap navbar hide after scrolling for 300px? I found a code snippet here that hides the navbar on scroll, but it hides immediately. How can I modify it to hide only after scrolling 300px? HTML: <nav class="autohide ...

Styling Form validation with Ant Design

Can a className prop be included in the Form.Item validation? <Form.Item name="username" rules={[ { required: true, message: '...' }, className="customValidation" //<- attempting to add a className but it is not fu ...

What is the best way to create a Div element that functions as a button, becoming active when clicked while deactivating all other Div elements

function toggleButton1() { $("#button1").toggleClass("button-active button-inactive"); $("#button2").toggleClass("button-inactive button-active"); $("#button3").toggleClass("button-inactive button-active"); } function toggleButton2() { $("#butto ...

The Backstretch jQuery plugin seems to be malfunctioning

My goal is to achieve a full-screen background image using the Backstretch jQuery plugin on my homepage. Here's the code I've implemented: <div class="startslide"> <script> $.backstretch('IMG_3628.jpg'); </script> < ...

How to obliterate an array element in JavaScript

Hello everyone, I am faced with an array of objects that I need to destructure. Below is a snippet from the array: [ { "Area": "Werk Produktivität [%] - Target", "Jan": 86.21397507374327, "Feb": 86.057 ...

Tips for applying and removing classes using an anchor tag

When I click on an anchor, I want it to add a specific class. This is my current markup: <ul> <li> <a href="<?php echo base_url()?>home/promos/call" class="promo-call"></a> </li> ...

How to reset a form in AngularJS using either HTML or a built-in directive

Within a standard modal popup in Bootstrap, I have implemented a form consisting of input fields, a submit button, a cancel button, and a close-icon. When selecting the name from an Object data-list using ng-repeat, the popup containing the form will displ ...

Tips for concealing an entire row of a table with Jquery

I am currently working on a system that involves a table with anchor tags named original and copy in each row. By clicking on these anchor tags, we are able to update the database whether the item is an original or a copy using ajax. However, I am facing a ...

Using Facebook authentication in React Native

Currently developing a React Native app and aiming to incorporate Facebook login functionality. The back-end logic for user authentication is handled by an API in Node.js. Utilizing passport.js to enable users to log in using either Facebook or Email cre ...

Shifting hues of dots within a grid according to the passing of time

As a newcomer to the world of coding, I have conceptualized an idea for a visually appealing clock. My goal is to visually represent the passage of time throughout the day. To achieve this, I have devised a grid system where each dot on the grid represents ...

Having difficulty rendering JSON data on an HTML webpage

Currently, I am working on an API App that utilizes the Foursquare API. With the help of my getRequest function, I am able to obtain results in JSON format, which are then displayed in my console.log. However, the challenge lies in parsing the data from J ...

html text alignment in the center

Is there a way to align text in the center without shifting the starting position of the first letter? before text 1 text text text 2 text text after ...

Troubleshooting issues with Angular's scope functionality

Here is my controller: angular.module('app', []) .controller('ctrl', ['$scope', function ($scope) { $scope.daysPerMonth = new Date(year, month).getDate(); }] ); This is the corresponding html: <div ng-app> <h1&g ...

The Slice method is malfunctioning after the array has been filtered

I am currently working on creating a news portal app using Next JS, Redux, mongoose, and Express. My Issue is: While I am able to filter specific items from an array successfully, I encounter problems when attempting to display a specific number of items, ...

Various style sheets are used for the production and staging environments

Is there a way to set up different styles for staging in node environments? Let's say I have the following scss files: scss/style.scss scss/theme.scss scss/green.scss After compiling, it gives me: style.scss Now, I'd like to change the style ...