-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject1JavaScript.js
More file actions
63 lines (55 loc) · 1.61 KB
/
Project1JavaScript.js
File metadata and controls
63 lines (55 loc) · 1.61 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
if (window.openDatabase) {
//Create the database the parameters are 1. the database name 2.version number 3. a description 4. the size of the database (in bytes) 1024 x 1024 = 1MB
var db = openDatabase("mydb", "1.0", "my first database", 1024 * 1024);
db.transaction(function (tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS receiptVFINAL (type, value)");
});
}
function myFucntionAdd() {
var li0 = document.getElementById("li1").value;
var tranType0 = [
"Images",
"GPS",
"Checkbox",
"Checklist",
"Dropdown",
"Number",
"Radio",
"Text",
"Media Comment",
"Text Comment",
];
db.transaction(function (tx) {
tx.executeSql("DELETE FROM receiptVFINAL");
tx.executeSql("CREATE TABLE IF NOT EXISTS receiptVFINAL (type, value)");
});
db.transaction(function (tx) {
for (i = 0; i < tranType0.length; i++) {
var y = Number(document.getElementById("li" + i).value).toFixed(2);
console.log(y);
tx.executeSql("INSERT INTO receiptVFINAL (type, value) VALUES (?, ?)", [
tranType0[i],
y,
]);
if (isNaN(y)) {
alert("Please Enter Numbers");
break;
}
}
tx.executeSql(
"SELECT SUM(value) as value FROM receiptVFINAL",
[],
function (tx, results) {
var len = results.rows.length,
i;
console.log(results);
console.log(tx);
for (i = 0; i < len; i++) {
var totalAmount = results.rows.item(i).value;
console.log(totalAmount);
document.getElementById("totalValue").value = totalAmount.toFixed(2);
}
}
);
});
}