-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrichard code form.js
More file actions
59 lines (53 loc) · 2.41 KB
/
richard code form.js
File metadata and controls
59 lines (53 loc) · 2.41 KB
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
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyDUEtIxfIU6vDQzQJXospI5maAQMmxgY6g",
authDomain: "my-coding-feedback.firebaseapp.com",
databaseURL: "https://my-coding-feedback-default-rtdb.firebaseio.com",
projectId: "my-coding-feedback",
storageBucket: "my-coding-feedback.firebasestorage.app",
messagingSenderId: "1082139342258",
appId: "1:1082139342258:web:e9d104e5afc7fe3eb960ab",
measurementId: "G-158XZGNT07"
};
// Initialize Firebase
const app = firebase.initializeApp(firebaseConfig);
var database = firebase.database()
document.getElementById("submitButton").addEventListener("click", function () {
console.log("submit clicked");
if (document.getElementById("nameInput").value == "" || document.getElementById("formContent").value == "") {
document.getElementById("status").innerText = "Please fill in all the things before submit";
setTimeout(function () {
document.getElementById("status").innerText = "";
},3000)
} else {
var data = {
name: document.getElementById("nameInput").value,
content: document.getElementById("formContent").value,
time: new Date().toUTCString()
}
database.ref("UserFeedbacks").push(data).then(function () {
document.getElementById("status").innerText = "Submitted";
localStorage.removeItem("input");
localStorage.removeItem("feedbackNameInTheMainWebsite");
document.getElementById("nameInput").value = ""
document.getElementById("formContent").value = ""
setTimeout(function () {
document.getElementById("status").innerText = "";
},3000)
})
}
})
window.onload = function () {
document.getElementById("formContent").value = localStorage.getItem("input");
document.getElementById("nameInput").value = localStorage.getItem("feedbackNameInTheMainWebsite");
}
document.getElementById("formContent").addEventListener("input", function () {
localStorage.setItem("input", document.getElementById("formContent").value);
console.log("saved")
});
//
document.getElementById("nameInput").addEventListener("input", function () {
localStorage.setItem("feedbackNameInTheMainWebsite", document.getElementById("nameInput").value);
console.log("saved name");
});