Initiate guestbook functions

This commit is contained in:
Helen Chong 2024-05-19 14:41:02 +08:00
parent 7a9d062e60
commit 89b08094f8
1 changed files with 16 additions and 1 deletions

View File

@ -16,7 +16,6 @@ const nameInputEl = document.querySelector('#name-input');
const emailInputEl = document.querySelector('#email-input'); const emailInputEl = document.querySelector('#email-input');
const websiteInputEl = document.querySelector('#website-input'); const websiteInputEl = document.querySelector('#website-input');
const msgInputEl = document.querySelector('#message-input'); const msgInputEl = document.querySelector('#message-input');
const publishBtn = document.querySelector('.gb__form--submit');
const messageListEl = document.querySelector('.gb__message--list'); const messageListEl = document.querySelector('.gb__message--list');
// Initiate guestbook message object // Initiate guestbook message object
@ -29,15 +28,31 @@ let messageObj = {
replies: [], replies: [],
}; };
// Form submission event
formEl.addEventListener('submit', (e) => { formEl.addEventListener('submit', (e) => {
e.preventDefault(); e.preventDefault();
clearInputEl(); clearInputEl();
console.log('Form submitted'); console.log('Form submitted');
}); });
// Clear input fields
const clearInputEl = () => { const clearInputEl = () => {
nameInputEl.value = ''; nameInputEl.value = '';
emailInputEl.value = ''; emailInputEl.value = '';
websiteInputEl.value = ''; websiteInputEl.value = '';
msgInputEl.value = ''; msgInputEl.value = '';
}; };
// Load data from the Firebase database
onValue(endorsementsInDB, (snapshot) => {});
// Prevent rendering any message more than once
const clearMessageListEl = () => {
messageListEl.innerHTML = '';
};
// Render each message
const renderMessage = (item) => {
const itemID = item[0];
const itemValue = item[1];
};