-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend.html
More file actions
99 lines (96 loc) · 3.29 KB
/
send.html
File metadata and controls
99 lines (96 loc) · 3.29 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./styles.css" rel="stylesheet">
<style>
button{
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
font-size: 2rem;
border-radius: 5px;
padding: 3%;
background-color: #888;
color: #eee;
border: none;
position: absolute;
bottom: 0px;
width: 100%;
}
</style>
<script>
if(!localStorage.getItem('uid')){
window.location.href='./login.html';
}
</script>
<title>Save a note</title>
</head>
<body>
<div class="add">
<a href="./index.html"><img src="./assets/logos/file-text.svg" width="30rem"></a>
</div>
<div class="line"></div>
<div class="container" style="display: flex; align-items: center; flex-direction: column;">
<h1>Add a Note</h1>
<div class="card" style="width: 50%; height: 60%;position: relative;">
<div class="head">
<input type="text" placeholder="Note Title" id="title" style="font-size: 2rem;">
</div>
<hr>
<div class="body" style="height:auto; margin-bottom: 0;">
<textarea rows='6' id="message" placeholder="Enter your message here" style="font-size: 2rem; height: 100%;"></textarea>
</div>
<button>Save</button>
</div>
<span id="save-message" style="color: #0f0;font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;display: none;">Saved Successfully!</span>
<!-- <h1>Send Data</h1>
<div class="form">
<label>Name</label>
<input type = "text">
<label>Email</label>
<input type = "text">
<label>Message</label>
<textarea></textarea>
<button>Submit</button>
</div>
<a class = "view" href = "fetch.html">View Data</a> -->
</div>
<!-- add firebase CDN -->
<script src="https://www.gstatic.com/firebasejs/9.12.1/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.12.1/firebase-database-compat.js"></script>
<script>
const firebaseConfig = {
databaseURL: "https://test-9e2b7-default-rtdb.asia-southeast1.firebasedatabase.app/"
}
firebase.initializeApp(firebaseConfig)
const database = firebase.database()
const submit = document.querySelector('button');
submit.onclick = () => sendData()
function sendData(){
const date=new Date();
var name = document.getElementById('title');
var email = date.toISOString();
var message = document.getElementById('message');
// send data
var listRef = database.ref('messages/')
var newRef = listRef.push()
newRef.set({
'uid' : localStorage.getItem('uid'),
'name': name.value,
'email': email,
'message': message.value
})
console.log("Data sent");
setTimeout(()=>{
document.getElementById('save-message').style.display='block';
}, 1000)
setTimeout(()=>{
document.getElementById('title').value=null;
document.getElementById('message').value=null;
document.getElementById('save-message').style.display='none';
}, 3000)
}
</script>
</body>
</html>