Tips for saving information from a constantly changing table into a database

I'm currently exploring options for storing data from a dynamic table into a database.

Here's the scenario: I'm in the process of creating a system to manage drivers' journeys. The system will track the driver's workday, dividing it into different intervals such as driving time, meal breaks, waiting time, etc. All these intervals are specified in HH:MM format and will be stored in separate tables, similar to the layout shown in the following image:

Journey Control

The input data (hours) for each table can vary depending on the driver's schedule for the day. My goal is to capture and save these hours in a database.

My current approach involves collecting all the hours after the user completes the input process. However, I am facing the challenge of how to store this data without having predefined field names.

Additional details: I am utilizing Java, SpringBoot, and Thymeleaf for the development.

JourneyControl.RegisterHourJourney = (function() {
    // JavaScript code block
}());
$(function() {
    var RegisterHourJourney = new JourneyControl.RegisterHourJourney();
    RegisterHourJourney.start();
});
<body>
<section layout:fragment="conteudo">
<div class="page-header">
<!-- html content -->
<!-- more HTML content -->
</form>
</div>
</section>
<th:block layout:fragment="javascript-extra">
<!-- scripts included here -->
</th:block>
</body>

Answer №1

An illustration of meal planning:

When you insert a new row, assign it a name using the format name="meal[" + nextMeal + "]". This naming convention will link your new meal to a list of meals in the controller upon form submission.

To determine the appropriate value for nextMeal, follow this approach:

var nextMeal = 0;           
while($("tr[name='nextMeal[" + nextMeal + "]']").length){
    nextMeal++;
} 

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

Utilizing CSS, Javascript, and Jquery to Toggle a DIV's Visibility Based on Clicking Either of Two Images

Need help with showing and hiding divs based on image clicks. Have 2 images (Image_A and Image_B) and 2 hidden Divs (Div_A and Div_B). If Image_A is clicked, show Div_A. If Image_B is clicked, hide Div_A and show Div_B. This should work both ways, ensurin ...

What is the best method for swapping out an iframe with a div using Javascript?

Having an issue with loading an external HTML page into an iFrame on my website. Currently facing two main problems: The height of the iFrame is fixed, but I need it to adjust based on the content's height. The content inside the iFrame does not inh ...

Creating a dynamic drag-and-drop layout in React using react-grid-layout

Utilizing the react-grid-layout package for implementing drag-drop and resize components, I have successfully achieved the functionality outlined in the documentation. Description of My Issue My challenge lies in creating a dynamic UI where the layout is ...

Can you explain the purpose of the `--save` command in NPM 5.0 and above?

Historically, the --save flag was utilized to include a package in the package.json. However, with the release of NPM 5, packages are now automatically added upon installation: What is the --save option for npm install?. Therefore, does the save flag hav ...

Running a script only if it is visible in the viewport

Is it possible to execute a JavaScript only when it is in the browser viewport? For example, if I have a script at the bottom of a page, can I make it load only when the user scrolls all the way to the end? I've come across solutions for loading imag ...

Issue 415: The battle between x-www-form-urlencoded and JSON

The online application allows for 'application/json' format, however when using .ajax() with dataType set to 'json', it attempts to send data in 'application/x-www-form-urlencoded' format. What could be causing this behavior? ...

The node experiences a crash when the redis-server goes offline

Struggling with a persistent issue here. Despite reading numerous documents and posts from others on the same topic, I can't seem to find a solution to prevent this problem. I am intentionally shutting down the redis server to avoid potential disaster ...

There seems to be a column in the MySQL INSERT query that is unidentifiable and does not exist in the list of fields

id and cost are required as integers and cannot be left empty. I encountered the following error message: 'Error: ER_BAD_FIELD_ERROR: Unknown column 'undefined' in 'field list'' var sql = "INSERT INTO Paintings(` ...

Can a correctly typed text alter the image?

I am working on a feature where the image changes when the user enters the correct text, indicating that it was typed correctly. However, I am facing an issue where if the first two characters are entered correctly but the third one is not, the image still ...

Enhance Your Jekyll Site with the Minimal Mistakes Theme Plugin

Hi there! I'm relatively new to website programming and could really use some assistance. I've been attempting to integrate the jekyll-lunr-js-search (https://github.com/slashdotdash/jekyll-lunr-js-search) into the minimal-mistakes theme, but I&a ...

Understanding Semantic Versioning (Semver) - A guide to properly Semvering major functional enhancements while maintaining backwards compatibility

It is my understanding that when using X.Y.Z, X is only changed for breaking updates while Y is reserved for backward compatible functional modifications. Therefore, can I infer correctly that even if my update involves a significant enhancement to functi ...

Generating div elements dynamically and applying styles

Generating a div dynamically and adding style to it var newDiv = document.createElement('div'); newDiv.setAttribute("id","dynamic-div"); document.body.appendChild(newDiv); // Simulating dynamic ajax content loading $(document).ready(function () ...

What is the correct method for calculating the sum of one input field and multiple output fields?

I have a single input field and multiple calculated output fields using JavaScript :Click here to view the screenshot of the calculated problem You can see the live preview on this link: . When you visit this link, enter "Base on your annual bill amount: ...

Guidance on dividing children in an object into distinct arrays

So I have an interesting challenge while working on my project. I need help figuring out how to split a Javascript Object like the one below: { field1: { field2: { field3: "value 1", field4: "value 2" ...

Attributes for 'v-bind' directives must have a value specified

Struggling to implement a tree structure in vue.js and encountering an issue with element props. Any assistance would be greatly appreciated. I've attempted using :content="{{tempCont}}" as well as content="{{tempCont}}", but neither approach proved ...

jQuery does not pass data to bootstrap modal

I am currently working with the full calendar feature. Within this framework, I have implemented a modal that allows users to insert new events: <div id="fullCalModal_add_appointment" class="modal fade"> <div class="modal-dialog"> ...

Exploring the world of JSON on the internet

Hello there! I'm currently working on a project similar to . However, I am facing difficulties when integrating my code with a discord bot. I am questioning whether it is possible to host JSON data online directly with the code snippet below: documen ...

The Hull.js Node.js npm module now offers convex hull computations instead of concave hull calculations

For my project, I am utilizing the node.js module called hull.js to compute a concave hull. However, when following the steps outlined in the "How it works" section on this link, the algorithm seems to halt at the 2nd step, resulting in a convex hull ins ...

Creating an event listener with a dynamic name

I'm in the process of developing a customizable button bar where I need to attach onclick event listeners to each button dynamically. The functions to be assigned should have names provided by the button's data-function attribute. … <div cl ...

Managing global HTTP response errors on Vue/axios using Vuex

I've encountered an issue in my VueJS SPA where a strange limbo state occurs. The application fails to recognize that the JWT token has expired, leading it to still display as if the user is logged in. This typically happens after periods of hibernati ...