-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
69 lines (62 loc) · 2.16 KB
/
app.js
File metadata and controls
69 lines (62 loc) · 2.16 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
60
61
62
63
64
65
66
67
68
69
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js";
import {
getFirestore,
collection,
addDoc,
} from "https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore.js";
const firebaseConfig = {
apiKey: "AIzaSyAWBg3ZpkbvVj5pr4jZNIhrWjMOv7TTjiQ",
authDomain: "surveyform-2188f.firebaseapp.com",
projectId: "surveyform-2188f",
storageBucket: "surveyform-2188f.appspot.com",
messagingSenderId: "579168167791",
appId: "1:579168167791:web:86a478429cc85ea68d2a9a",
measurementId: "G-Y5LNCFZ4XK",
};
const app = initializeApp(firebaseConfig);
const db = getFirestore();
const colRef = collection(db, "formdata");
const form = document.querySelector(".input-fields");
const name = document.querySelector("#name");
const DOB = document.querySelector("#DOB");
const email = document.querySelector("#email");
const curKnowledge = document.querySelector("#curKnowledge");
const aim = document.querySelector("#aim");
const dreamProject = document.querySelector("#dreamProject");
const preferredLocation = document.querySelector("#location");
form.addEventListener("submit", (event) => {
event.preventDefault();
const radioButtons = document.querySelectorAll('input[type="radio"]');
let selectedRadioValue;
// Find the selected radio button value
radioButtons.forEach((radioButton) => {
if (radioButton.checked) {
selectedRadioValue = radioButton.value;
}
});
const checkboxElements = document.querySelectorAll(
'input[type="checkbox"]:checked'
);
const selectedCheckboxValues = [];
checkboxElements.forEach((checkbox) => {
selectedCheckboxValues.push(checkbox.value);
});
addDoc(colRef, {
name: name.value,
DOB: DOB.value,
email: email.value,
curKnowleadge: curKnowledge.value,
aim: aim.value,
dreamProject: dreamProject.value,
domain: selectedRadioValue,
languages: selectedCheckboxValues,
preferredLocation: preferredLocation.value,
})
.then((result) => {
form.reset();
alert("your data was successfully stores to the database");
})
.catch((err) => {
alert(err);
});
});