-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
44 lines (38 loc) · 1.18 KB
/
app.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
var tblRecord = [];
$(document).ready(function() {
createTableRow();
$("#save").click(function() {
var fname = $("#fname").val();
var sub = $("#sub").val();
var date = $("#date").val();
var tblObj = { fname: fname, sub: sub, date: date };
tblRecord.push(tblObj);
console.log(tblRecord);
//convert us object to json <string></string>
localStorage.tblData = JSON.stringify(tblRecord);
createTableRow();
});
});
// function createTableRow(){}
var createTableRow = function() {
//converst json string to js object
try {
tblRecord = JSON.parse(localStorage.tblData);
$("tbody").empty();
for (var i = 0; i < tblRecord.length; i++) {
var fname = tblRecord[i].fname;
var sub = tblRecord[i].sub;
var date = tblRecord[i].date;
var tblrow = "<tr><td>" +
fname + "</td><td>" +
sub + "</td><td>" +
date + "</td></tr>";
$("tbody").append(tblrow);
}
$("#fname").val("");
$("#sub").val("");
$("#date").val("");
} catch (e) {
console.log('null');
}
}