Initiate function to submit form and clear input fields

This commit is contained in:
Helen Chong 2024-05-19 14:30:19 +08:00
parent a67a870c42
commit 7a9d062e60
3 changed files with 27 additions and 5 deletions

View File

@ -1,5 +1,3 @@
console.log("Guestbook script successfully loaded");
// Import Firebase // Import Firebase
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-app.js' import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-app.js'
import { getDatabase, ref, push, onValue, update } from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-database.js' import { getDatabase, ref, push, onValue, update } from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-database.js'
@ -29,4 +27,17 @@ let messageObj = {
message: '', message: '',
timestamp: '', timestamp: '',
replies: [], replies: [],
};
formEl.addEventListener('submit', (e) => {
e.preventDefault();
clearInputEl();
console.log('Form submitted');
});
const clearInputEl = () => {
nameInputEl.value = '';
emailInputEl.value = '';
websiteInputEl.value = '';
msgInputEl.value = '';
}; };

View File

@ -4,7 +4,7 @@
<subtitle>Leilukin&#39;s personal website.</subtitle> <subtitle>Leilukin&#39;s personal website.</subtitle>
<link href="https://leilukin.neocities.org/feed.xml" rel="self"/> <link href="https://leilukin.neocities.org/feed.xml" rel="self"/>
<link href="https://leilukin.neocities.org"/> <link href="https://leilukin.neocities.org"/>
<updated>2024-05-19T06:23:25Z</updated> <updated>2024-05-19T06:29:00Z</updated>
<id>https://leilukin.neocities.org</id> <id>https://leilukin.neocities.org</id>
<author> <author>
<name>Leilukin</name> <name>Leilukin</name>

View File

@ -1,5 +1,3 @@
console.log("Guestbook script successfully loaded");
// Import Firebase // Import Firebase
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-app.js' import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-app.js'
import { getDatabase, ref, push, onValue, update } from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-database.js' import { getDatabase, ref, push, onValue, update } from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-database.js'
@ -29,4 +27,17 @@ let messageObj = {
message: '', message: '',
timestamp: '', timestamp: '',
replies: [], replies: [],
};
formEl.addEventListener('submit', (e) => {
e.preventDefault();
clearInputEl();
console.log('Form submitted');
});
const clearInputEl = () => {
nameInputEl.value = '';
emailInputEl.value = '';
websiteInputEl.value = '';
msgInputEl.value = '';
}; };