-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
41 lines (34 loc) · 1.32 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
document.addEventListener('DOMContentLoaded', function () {
const addComBack = document.getElementById('addComBack');
const addCom = document.getElementById('addCom');
const closePopup = document.getElementById('close');
const comment = document.getElementById('comment');
const username = document.getElementById('username');
function openAddCom() {
addComBack.style.display = 'flex';
}
function closePopupFunc() {
addComBack.style.display = 'none';
comment.value = '';
username.value = '';
}
function addComment(event) {
event.preventDefault();
const commentText = comment.value;
const usernameText = username.value;
if (commentText && usernameText) {
console.log(`Username: ${usernameText}, Comment: ${commentText}`);
closePopupFunc();
} else {
alert('Please enter both comment and username.');
}
}
document.querySelector('.commenting').addEventListener('click', openAddCom);
closePopup.addEventListener('click', closePopupFunc);
document.getElementById('comment-form').addEventListener('submit', addComment);
addComBack.addEventListener('click', function (event) {
if (event.target === addComBack) {
closePopupFunc();
}
});
});