Generating new tr elements and storing them using JavaScript

I'm relatively new to coding, especially when it comes to JS. I am currently working on a program that is designed to calculate input values and display the results (along with the date) in a table. Every time there is a new input, a new entry should be added to the table. Additionally, the table data should be saved and retrieved whenever the page is reloaded.

Currently, I am facing an issue where only the first entry is being saved. It is vital that all the data in the table gets saved. Does anyone have any suggestions or solutions for this problem? Thank you.

Below is the code snippet:

// your unique JavaScript code goes here
// your unique CSS code goes here
<html>
<head>
    <!-- your HTML code goes here -->
</head>
<body>
    <!-- your unique HTML content goes here -->
    <script src="your-script.js"></script>
</body>
</html>

You can also view the code on your website name.

Answer №1

Here is a basic structure for you to visualize how we can move forward if your requirements are clear. I have created two types of arrays, a simple array (dateArray and amountArray) along with dailyInputArray as an array of objects (dailyInput ). It's important to note that for improved security, it's recommended to store the data in a MySQL database. Due to potential restrictions when using localstorage, please ensure to test the code in your preferred code editor.

let amountArray=[]
let dateArray=[]
let dailyInput={}
let dailyInputArray=[]
let retrieveDailyInputValues = localStorage.getItem('DailyInputValues');
retrieveDailyInputValues = JSON.parse(retrieveDailyInputValues)
console.log(retrieveDailyInputValues)
if(retrieveDailyInputValues && retrieveDailyInputValues.length!=0){
    dailyInputArray=retrieveDailyInputValues
}else{
    dailyInputArray=[]
}
// rest of the JavaScript code goes here 
*{
  box-sizing: border-box;
  font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}
/* Rest of the CSS styles */
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="veiwport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="FinanceTool.css">
    <title>Finance_Tool</title>
</head>
<body>
<main id="tool">
    <h1 class="heading">Simple Finance Tool</h1>
<p id="value-message-negative" class="value-message">Your number is negative. This will be calculated as a financial loss.</p>
<p id="value-message-positive" class="value-message">Your number is positive. This will be calculated as a financial gain.</p>
                            // HTML Code block continues 

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

Global variable in Npm CLI

I'm working on a CLI tool that heavily relies on storing a unique identifier (uid). I attempted to use fs to store the uid; however, the file was created in the directory where the command was executed. #!/usr/bin/env node const program = require("co ...

Creating a function to target a specific HTML class in Angular can be achieved by utilizing Angular

Can a function be created for the entire class instead of adding it to each individual line? In this case, I have a class called "dropdown-item" for each link with this class, and I want them all to have the same function. <li class="nav-item dr ...

A guide on integrating Javascript and CSS files in Express.js

I'm currently running a simple node server from a page.js file as part of a system setup test. Here's the code snippet: var express = require('express'); var app = express(); app.get('/', function(req, res) { res.sendFil ...

Beginner looking to create a rock, paper, scissors game using arrays in JavaScript

As a recent addition to this community and as someone who just started learning JavaScript 4 weeks ago, I have progressed from html to css and now onto JavaScript. My current project involves creating an array-based rock-paper-scissors game with minimal m ...

The success function is failing to display the Ajax response

Is there a way to correctly display the ajax response of my code? I noticed that when using async=true, only the last value of yy is shown. However, I want to display it for all values from 0 to a. Interestingly, everything works fine when using async=fa ...

Utilizing Prototype in Node.js Modules

Currently, I am working on a project involving multiple vendor-specific files in node. These files all follow a similar controller pattern, so it would be more efficient for me to extract them and consolidate them into a single common file. If you're ...

Issues with jQuery toggle functionality have been reported specifically on the iPhone8 and other iOS devices

Hi everyone, I'm facing an issue with the header on my website. It displays a hamburger menu on small screens, and while it works perfectly on PCs and Android phones, it's unresponsive on iOS, specifically on my iPhone 8. I've tried using va ...

Preventing nested prototype methods from being transferred between objects in a WebWorker

My challenge is to reserialize an object from a WebWorker while maintaining the same definitions. However, upon receiving the message, all of the prototype functions are lost. The current solution I have only works for first level prototype functions, bu ...

Using Python to access files

I have developed a system that allows me to load image files from HTML. However, after selecting a file and loading it from the front end, I am in need of a Python API to read the selected image file. How can I establish a connection between Python and HTM ...

Designing a website's layout with HTML and CSS

I am having trouble developing a concept depicted in the image below. Here is what I have accomplished so far: https://jsfiddle.net/o0zmtr3q/2/. I am struggling to make each box unique, especially with the layout where the text is positioned differently in ...

The Clash of Form Action and JavaScript

Can someone help me with this issue? I have a form and a script to trigger an alert message. The code I'm using is working well: <input id="autocomplete" class="input_message" type="text" name="message" autocomplete="off" placeholder="...typ ...

Techniques for Grouping an Array of Objects by a Specific Value Key in Angular

I have the following array that needs to be grouped by section_name in HTML. Additionally, I need to first check if the length of the array values for section_name is greater than zero before displaying the results grouped by section_name. I hope my expl ...

using jQuery to retrieve JSON data containing nested arrays

I'm currently working with a music player that requires fetching JSON values dynamically from a page. The issue I am facing is the format of the JSON, which looks something like this: {"audios":[{"audio":{"name":"makakyala","audio":{"audio":{"url":"/ ...

Manipulate HTML elements using JavaScript when a key is being held down

I'm currently developing a simple game using vueJS for the frontend. I have successfully created all the necessary objects and now my goal is to enable their movement when a key is pressed. However, I am facing an issue where the object only moves on ...

Tips for positioning text in front of images

This is the code I am currently working with: .left-ul { margin-left: 10px!important; display: inline-block!important; vertical-align: top; width: 350px; } .iconic { padding ...

find all the possible combinations of elements from multiple arrays

I have a set of N arrays that contain objects with the same keys. arr[ {values:val1,names:someName},   {values:val2,names:otherName}, ] arr2[   {values:valx,names:someNamex}, {values:valy,names:otherNamey}, ] My goal is to combine all possible c ...

Using an array inside a for loop to follow the same structure

I am in need of prompt assistance on how to integrate my array into a for loop. Currently, my graph accepts the following as nodes: var classes = [ {"name":"test.cluster1.item1"}, {"name":"test.cluster1.item2"}, {"name":"test.cluster1.item3"} ...

Looking to extract data from an HTML form?

In my HTML form, I am dynamically creating elements and setting their name and value attributes. When I try to access the value using document.formname.nameoftheelement.value, I receive an error stating that the value is undefined. I then attempted to us ...

Is there a different way to retrieve the tag name of an element besides using

Currently, I am dealing with an outdated version (Chromium 25) of chromium. My goal is to utilize the tagName method in order to retrieve the name of the specific HTML tag being used. While I am aware that Element.tagName functions for versions 43 and ab ...

Evaluate numerical values using xsl:choose function

Using XSL version 1.0, I am populating an HTML table with percentage values from XML. My goal is to display the highlighted color of the percentages based on a condition, but the condition is not being processed as expected, leading to the exclusion of the ...