-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
27 lines (21 loc) · 939 Bytes
/
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
const commentForm = document.getElementById('comment-form');
const commentList = document.getElementById('comment-list');
const commentError = document.getElementById('comment-error');
commentForm.addEventListener('submit', function(event) {
event.preventDefault(); // Prevent default form submission
// Get comment text
const commentText = document.getElementById('comment').value;
// Check if comment is empty
if (commentText.trim() === '') {
commentError.textContent = "Please enter a comment.";
return;
}
// Simulate adding comment to the page (for demonstration)
const newComment = document.createElement('div');
newComment.classList.add('comment'); // Add CSS class for styling (optional)
newComment.textContent = commentText;
commentList.appendChild(newComment);
// Clear comment text area and error message
document.getElementById('comment').value = '';
commentError.textContent = '';
});