What is the best way to save data from a date and time input field?

I am currently in the process of developing a reminder application, but I am facing an issue with storing the date and time information. As of now, I can only save the name and description of the reminders. My immediate goal is to successfully save this data into local storage and tackle the retrieval aspect later on.

let reminders = [];
const addReminders = (ev) => {
  ev.preventDefault();
  let reminder = {
    ReminderInput: document.getElementById('ReminderInput').value,
    InfoInput: document.getElementById('InfoInput').value
  }
  localStorage.setItem('ReminderInput', JSON.stringify(ReminderInput));
  localStorage.setItem('InfoInput', JSON.stringify(InfoInput));
  localStorage.setItem('DateInput'  JSON.stringify(DateInput));
}
document.addEventListener('DOMContentLoaded', () => {
  document.getElementById('btn').addEventListener('click', addReminders);
});
<form id="todoForm">
  <label for="ReminderInput">Reminder</label>
  <input class="u-full-width" type="text" id="ReminderInput">

  <label for="DateInput">Date</label>
  <input class="u-full-width" type="datetime-local" id="DateInput">

  <label for="InfoInput">Additional Information</label>
  <textarea class="u-full-width" type="text" placeholder="Remember to..." id="InfoInput"></textarea>
  
  <button type="button" id="btn" class="button-primary">Add Reminder</button>
</form>

Answer №1

Check out this code that needs fixing, see the screenshot for reference:

    let reminder = {
        ReminderInput: document.getElementById('ReminderInput').value,
        InfoInput: document.getElementById('InfoInput').value,
        DateInput: document.getElementById('DateInput').value
    }
    localStorage.setItem('ReminderInput', JSON.stringify(reminder.ReminderInput));
    localStorage.setItem('InfoInput', JSON.stringify(reminder.InfoInput));
    localStorage.setItem('DateInput',JSON.stringify(reminder.DateInput));
}

https://i.sstatic.net/uEBjT.png

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

Extracting information from a Weather API and sharing it on Twitter

Can anyone help me troubleshoot my Twitter bot setup for tweeting out city temperatures? I attempted switching to a different API, but nothing seems to be resolving the issue. console.log('initiating twitter bot...') var Twit = require('t ...

Creating a dynamic memory allocation for a character array in C++

Exploring dynamic memory in C++ has been quite enlightening. The standard way of allocating and deallocating dynamically for different data types is intriguing. For instance: //For double, double* pvalue1 = nullptr; pvalue1 = new double; *pvalue1 = 17.3; ...

How can I add a character at a precise location while keeping the existing tags intact

Latest Update After further testing, it seems that the code performs well with a faux spacer, but runs into issues with the regex. The following scenarios work correctly: Selecting words above or below the a tag Selecting just one line directly above or ...

Issue with JSON or Jquery: Uncaught error message: Cannot access property 'error' as it is null

I am attempting to initiate an ajax call using the jQuery code provided below. However, when I try this in Chrome, I encounter an error that says 'uncaught typeerror cannot read property 'error' of null'. This prevents the preloader fr ...

"Combining the power of Angularjs and the state

I've been delving into Redux, mainly in the context of using it with React. However, I use AngularJS. Is there a compelling advantage to implementing Redux instead of handling state within AngularJS scope and letting Angular manage the bindings? ...

Update all jQuery scripts to dynamically loaded scripts

My collection of jQuery scripts is not equipped to handle dynamically loaded or created elements. While I could manually convert each script and include the .live() function, I'm curious if there's a way to automatically simulate the live functio ...

What is the best way to delete an element from two arrays while keeping their original order intact?

Currently, I am faced with the task of removing 2 items from 2 separate arrays. One array contains values while the other does not, but both arrays have the same order. (I am using discord.js for this). To view the code snippet, you can visit - Unfortun ...

Preventing PowerShell from Unrolling an Array in Subsequent Script Invocations

I'm facing a challenge with my PowerShell scripts where I need to run a specific batch of commands in PowerShell 5 due to DLL compatibility issues, despite running most code in PowerShell 7 for better Unicode support. Unfortunately, using dot sourcing ...

How to determine if a div is within the viewport with jQuery

I am attempting to utilize jQuery to determine if Div RED is currently visible within the viewport, and if not, then check for the visibility of Div ORANGE. The function I have implemented works perfectly when there is only one IF statement, but as soon as ...

Laravel error: Offset type is not valid

Implementing Ajax code in Laravel using a controller: <?php namespace customapp\Http\Controllers; use Illuminate\Http\Request; use customapp\Store; use DB; class CustomAjaxController extends Controller { public function ...

Enhancing PHP function speed through pre-compilation with Ajax

I am curious about compiling server side functions in PHP with Ajax, specifically when multiple asynchronous calls are made to the same server side script. Let's consider a PHP script called "msg.php": <?php function msg(){ $list1 = "hello world ...

Tips for displaying axios status on a designated button using a spinner

Utilizing a v-for loop to showcase a list of products retrieved from an API request. Within the product card, there are three buttons, one for adding items to the cart with a shopping-cart icon. I aim for the shopping-cart icon to transform into a spinner ...

Using VueJS to navigate to a specific route and pass parameters along with the

I'm a complete beginner when it comes to VueJS. Can someone please help me figure out how to access the deviceId in the Device component within vuejs? I've noticed that the deviceId in the h1 tag is not displaying on the Device component page. ...

Next.js version 10 Internationalization - default locale always returned by getStaticProps

I'm in the process of setting up a new project with the latest version of Next.js and implementing internalisation using domain routing as described here. My configuration within the next.config.js file looks like this: i18n: { locales: [' ...

How can JavaScript Regular Expressions be used for Form Validation?

For my registration form, I am including fields such as userid, name, email, password, confirm password, and affiliation. Using regular expressions in JavaScript, I am validating these fields. I am attempting to display any validation errors within the for ...

handlebars - How to merge all elements from one array into another array as the value of a single element

In my JSON record file, there is an element called "custitem_list" with the following structure: "custitem_list": [ { "internalid": "1", "name": "FLAT AND DULL" }, { &quo ...

Should I fork and customize npm package: Source or Distribution? How to handle the distribution files?

Currently, I am in the process of developing a VueJS web application. Within this project, there is a module that utilizes a wrapper for a JavaScript library obtained through npm and designed to seamlessly integrate with VueJS. However, it doesn't com ...

Switching downlink to top link when scrolling downwards

I have a downward scrolling link on my homepage that moves the page down when clicked by the user. However, I am struggling to make it change to a "back to top" link as soon as the user scrolls 10 pixels from the top. Additionally, I am having trouble with ...

Checking for duplicates in a TypeScript array of objects

I am facing a requirement where I must check for duplicates among object items. Within the following Array of objects, I need to specifically look for duplicates in either the "empno" or "extension" properties. If any duplicates are found, an error should ...

Ways to eliminate HTML elements from displayed content

I need help removing the <p> tags from comment text that is rendered. When passing the content to a component as a prop, I am experiencing issues with the v-html directive not working correctly. How can I render the content without the HTML tags? C ...