-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
50 lines (38 loc) · 1.32 KB
/
main.js
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
var config = {
apiKey: "AIzaSyDFvbGkbdl8NGJZLXEJ0YBu8g_Wu5BNLlo",
authDomain: "contactform-82a05.firebaseapp.com",
databaseURL: "https://contactform-82a05-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "contactform-82a05",
storageBucket: "contactform-82a05.appspot.com",
messagingSenderId: "753686371831",
appId: "1:753686371831:web:c578b3c145a2465e5462f2"
};
firebase.initializeApp(config);
var database = firebase.database();
function useDatabase() {
}
document.getElementById('reginfo').addEventListener('submit', submitForm);
//submite form
function submitForm(e){
e.preventDefault();
var contactnum = getInputVal('contactnum');
var street = getInputVal('street');
var database = firebase.database();
var alert = document.querySelector('.alert');
if(alert){
alert.style.display = 'block';
}
// Hide success message after 3 seconds
setTimeout(function() {
document.querySelector('.alert').style.display = 'none';
}, 3000);
// Create a new child in the database and set the inputted values
database.ref('users/' + street).update({
[contactnum]: true
});
// Clear form
document.getElementById('reginfo').reset();
}
function getInputVal(id){
return document.getElementById(id).value;
}