I have been struggling with this for some time now. I have several blocks with hourly time slots and I want to make sure every time a user types something and clicks the save button its saved and even after refreshing the page it still remains on the page until they decide to delete what is written and type something new in that box. my html code below and just so you know I just learning JS so any help will be appreciated.
let time = [];
const addText = (ev) => {
let newTime = {
timeData: document.querySelectorAll("#hour Block, #hourBlock1, #hourBlock2").value,
textData: document.querySelector('.text-input').value
}
time.push(newTime);
localStorage.setItem('My Time', JSON.stringify(time));
}
document.querySelector('.saveButton').addEventListener('click', addText);
document.querySelector('.text-input').value = localStorage.getItem('addText');
<div id="hourblock">
<div id>9A M</div>
<input data-hour="9" class="text-input" placeholder=""></inputs>
<button class="saveButton"><i class="far fa-save fa-2x"></i></button>
</div>
<div id="hourBlock1">
<div id>10AM</div>
<input data-hour="10" class="text-input" placeholder=""></inputs>
<button class="saveButton">
<i class="far fa-save fa-2x"></i>
</button>
</div>
<div id="hourBlock2">
<div id>11AM</div>
<input data-hour="11" class="text-input" placeholder=""></inputs>
<button class="saveButton">
<i class="far fa-save fa-2x"></i>
</button>
</div>