-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathform.js
More file actions
40 lines (31 loc) · 975 Bytes
/
form.js
File metadata and controls
40 lines (31 loc) · 975 Bytes
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
"use strict";
let data = {'articles':[]};
function loadArticles() {
try {
let storedData =
JSON.parse(localStorage.getItem('articleData'));
if (storedData !== null) {
data = storedData;
}
else {
console.log("No Text");
}
}
catch {}
}
$('#button-save-article').click(() => {
loadArticles();
let form = document.getElementById("articleForm");
let articleTitleEntry = form.articleTitle.value;
let articleTextEntry = form.articleText.value;
if (articleTextEntry !== '' && articleTitleEntry !== ''){
let item = {};
item.articleTitle = articleTitleEntry;
item.articleText = articleTextEntry;
data.articles.push(item);
localStorage.setItem('articleData', JSON.stringify(data));
}
form.articleTitle.value = '';
form.articleText.value = '';
window.location.href = "blog.html";
});