-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
102 lines (86 loc) · 3.75 KB
/
script.js
File metadata and controls
102 lines (86 loc) · 3.75 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// declare all cladd & id
let formAlert = document.querySelector('.alert');
let bookName = document.querySelector('#book-name');
let authorName = document.querySelector('#author-name');
let publishDate = document.querySelector('#publish-date');
let btn = document.querySelector('.btn');
let bookList = document.querySelector('.book-list');
let bookAlert = document.querySelector('#book-alert');
let authorAlert = document.querySelector('#author-alert');
let publishAlert = document.querySelector('#publish-alert');
// new data add event
btn.addEventListener('click', function(event) {
event.preventDefault();
// all error validation
if(bookName.value == '' && authorName.value == '' && publishDate.value == '') {
formAlert.classList.remove('d-none');
formAlert.innerHTML = 'Please fillup your all credential information!';
}
// single error validation
else if(bookName.value == '' && authorName.value !== '' && publishDate.value !== '') {
bookAlert.innerHTML = 'Please fillup your book name!';
authorAlert.innerHTML = '';
publishAlert.innerHTML = '';
formAlert.classList.add('d-none');
}
else if(bookName.value !== '' && authorName.value == '' && publishDate.value !== '') {
authorAlert.innerHTML = 'Please fillup your author name!';
bookAlert.innerHTML = '';
publishAlert.innerHTML = '';
formAlert.classList.add('d-none');
}
else if(bookName.value !== '' && authorName.value !== '' && publishDate.value == '') {
publishAlert.innerHTML = 'Please select your publish date!';
bookAlert.innerHTML = '';
authorAlert.innerHTML = '';
formAlert.classList.add('d-none');
}
// double error validation
else if(bookName.value !== '' && authorName.value == '' && publishDate.value == '') {
authorAlert.innerHTML = 'Please fillup your author name!';
publishAlert.innerHTML = 'Please select your publish date!';
bookAlert.innerHTML = '';
formAlert.classList.add('d-none');
}
else if(bookName.value == '' && authorName.value !== '' && publishDate.value == '') {
bookAlert.innerHTML = 'Please fillup your book name!';
publishAlert.innerHTML = 'Please select your publish date!';
authorAlert.innerHTML = '';
formAlert.classList.add('d-none');
}
else if(bookName.value == '' && authorName.value == '' && publishDate.value !== '') {
bookAlert.innerHTML = 'Please fillup your book name!';
authorAlert.innerHTML = 'Please fillup your author name!';
publishAlert.innerHTML = '';
formAlert.classList.add('d-none');
}
else {
// single alert disable
bookAlert.innerHTML = '';
authorAlert.innerHTML = '';
publishAlert.innerHTML = '';
// success alert
formAlert.classList.remove('d-none');
formAlert.classList.replace('alert-danger', 'alert-info');
formAlert.innerHTML = 'You have successfully added your information!'
// create new table row
const newRow = document.createElement('tr');
bookList.appendChild(newRow);
// create new book name
const newBook = document.createElement('td');
newBook.innerHTML = bookName.value;
newRow.appendChild(newBook);
// create ner author name
const newAuthor = document.createElement('td');
newAuthor.innerHTML = authorName.value;
newRow.appendChild(newAuthor);
// create new publish date
const newPublish = document.createElement('td');
newPublish.innerHTML = publishDate.value;
newRow.appendChild(newPublish);
// reset all data
bookName.value = '';
authorName.value = '';
publishDate.value = '';
}
});