-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascript.js
38 lines (38 loc) · 1.08 KB
/
javascript.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
var db = new PouchDB('http://localhost:5984/pouchdbtodo');
var id = Math.random();
var date = new Date();
function putdata(){
var tododata = document.getElementById('todo').value;
var todoobject = {
_id : 'todo_' + id,
value : tododata,
date : date
}
db.put(todoobject, function(err, response){
if(err){
return console.log(err);
}else{
console.log("database is updated");
}
})
}
var addbutton = document.getElementById('add');
addbutton.addEventListener('click', function(e){
putdata();
e.preventDefault();
})
// Displaying the data
db.allDocs({include_docs : true}, function(err, doc){
if(err){
return console.log(err);
}
else{
for(var i = 0; i < doc.rows.length; i++){
var display = document.getElementById('display');
var elementcreated = document.createElement('H1');
elementcreated.textContent = doc.rows[i].doc.value;
display.appendChild(elementcreated);
console.log(doc.rows[i].doc.value);
}
}
})