-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (47 loc) · 1.73 KB
/
Copy pathscript.js
File metadata and controls
55 lines (47 loc) · 1.73 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
let submit = document.querySelector("#submit");
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.1.0/firebase-app.js";
import { getDatabase, ref, set, push } from "https://www.gstatic.com/firebasejs/10.1.0/firebase-database.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyBhc0fk_t5q6xo4FySI9XXGHdEfLssCru8",
authDomain: "folder-24d4a.firebaseapp.com",
projectId: "folder-24d4a",
storageBucket: "folder-24d4a.appspot.com",
messagingSenderId: "256440210644",
appId: "1:256440210644:web:244b521bde9a1aa728d741",
measurementId: "G-32LGWTYVNN"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const database = getDatabase();
let dbRef = localStorage.getItem("Mobile");
const Title = document.getElementById("Title");
const Info = document.getElementById("Info");
function submitForm(e) {
e.preventDefault()
const DocTitle = Title.value;
const DocInfo = Info.value;
if (DocTitle && DocInfo) {
const usersRef = push(ref(database, dbRef));
set(usersRef, {
Title: DocTitle,
Info: DocInfo
})
.then(() => {
alert("Document Added Successfully 🥰");
location.reload();
Title.value = "";
Info.value = "";
})
.catch((error) => {
console.error("Error submitting data:", error);
});
} else {
alert("Please enter both a Title and a Details.");
}
}
submit.addEventListener("click", submitForm);