-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.js
46 lines (34 loc) · 1.03 KB
/
blog.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
var config = {
apiKey: "AIzaSyCAKNhHVoGUJLvTkCVYFP1NhtVC_3rFrwk",
authDomain: "blog-8844e.firebaseapp.com",
databaseURL: "https://blog-8844e.firebaseio.com",
projectId: "blog-8844e",
storageBucket: "blog-8844e.appspot.com",
messagingSenderId: "841236522958"
};
firebase.initializeApp(config);
var messageRef=firebase.database().ref('comments');
document.getElementById('blog').addEventListener('submit', submitForm);
function submitForm(e){
e.preventDefault();
var comment=getInputVal('comment');
var selectedGender;
document.getElementsByName("check").forEach(function(elm) {
if (elm.checked) {
selectedGender = elm.value;
}
})
// console.log(comment);
saveMessage(comment, selectedGender);
window.location.href="";
}
function getInputVal(id){
return document.getElementById(id).value;
}
function saveMessage(comment, selectedGender){
var newmessageRef=messageRef.push();
newmessageRef.set({
comment:comment,
checked: selectedGender
});
}