-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
109 lines (82 loc) · 2.37 KB
/
script.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
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
101
102
103
104
105
106
107
108
// console.log("hello Everyone")
class lib {
constructor(name, author, type) {
this.name = name;
this.author = author;
this.type = type;
}
};
class display {
static clear() {
let libform = document.getElementById("libform");
libform.reset()
}
static add(book) {
let tblBody = document.getElementById("tblBody");
let tblbodystring = `
<tr>
<td>${book.name}</td>
<td>${book.author}</td>
<td>${book.type}</td>
</tr>
`
tblBody.innerHTML += tblbodystring;
}
static vaidate(book) {
if (book.name == "") {
return false;
}
else{
return true;
};
if (book.author=="") {
return false
}
else{
return true
}
}
static shorerr(type,message){
let mssg =document.getElementById("errms");
mssg.innerHTML=`<div class="alert alert-${type} alert-dismissible fade show" role="alert">
<strong>Message!!</strong> ${message}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
`
setTimeout(() => {
mssg.innerHTML="";
}, 3000);
}
}
let libform = document.getElementById("libform");
libform.addEventListener("submit", libformsub);
function libformsub(e) {
e.preventDefault();
console.log("u have submitted the form");
let name = document.getElementById("bookName").value;
let author = document.getElementById("authorName").value;
let type = document.getElementById("type").value;
let fiction = document.getElementById("fiction");
let cp = document.getElementById("cp")
let cooking = document.getElementById("cooking");
if (fiction.checked) {
type = fiction.value.toUpperCase()
}
else if (cp.checked) {
type = cp.value.toUpperCase()
}
else if (cooking.checked) {
type = cooking.value.toUpperCase()
}
let book = new lib(name, author, type);
console.log(book);
if (display.vaidate(book)) {
display.clear();
display.add(book);
display.shorerr("success","your book is added in the list")
}
else {
console.log("hello")
display.shorerr("oops","your book cant be added in list")
}
}