-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.js
36 lines (32 loc) · 1.15 KB
/
start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
let showText = document.getElementById("show-text");
let hoursRegistered = document.getElementById("number-of-hours");
let commentToHoursRegistered = document.getElementById("comment");
let numberOfHours = document.getElementById("number-of-hours");
let counter = -1;
let hoursCounter = 0;
function getTimeSheet() {
//Get the previously saved values
return JSON.parse(localStorage.getItem("timeSheetForPerson")) || [];
}
function setTimeSheet(a) {
//Set values to localstorage
window.localStorage.setItem(`timeSheetForPerson`, JSON.stringify(a));
location.reload();
}
function saveHours(event) {
//Prevent form to send before the information has been saved
event.preventDefault();
//Check if validation set in input id="number-of-hours" has passed
if (numberOfHours.checkValidity()) {
// Save the current values
let todaysTimeSheet = {
hours: hoursRegistered.valueAsNumber,
comment: commentToHoursRegistered.value,
};
// Push the new values to the timeSheet-array and set in localstorage
let timeSheet = getTimeSheet();
timeSheet.push(todaysTimeSheet);
alert("timene er lagret");
setTimeSheet(timeSheet);
}
}