-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
143 lines (98 loc) · 3.54 KB
/
script.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
$(document).ready(function(){
//alert("this is a test")
$("#button").click(function(){
var thisItem = $("#whatItem").html();
//document.getElementById("whatItem").innerHTML
var thisAmount = $("#quantity").val();
console.log(thisAmount)
//document.getElementById("quantity").value
var thisCost = Number($("#cost").html().replace(/[^0-9\.]+/g,""));
var myTotal = "$"+thisAmount * thisCost;
console.log(myTotal);
addRow(thisItem, thisAmount, thisCost, myTotal)
//calculate here
//this add them to a static row
// $("#item2").html(thisItem);
// $("#amount2").html(thisAmount);
// $("#price2").html(thisCost);
// $("#result2").html(myTotal);
// but I need to generate cells dynamicall with the add button
function addRow(thisItem, thisAmount, thisCost, myTotal) {
$("#orders").append("<tr><td>"+thisItem+"</td><td>"+thisAmount+"</td><td>"+thisCost+"</td><td>"+myTotal+"</td></tr>")
// var table = document.getElementById("#orders");
// var rowCount = table.rows.length;
// var row = table.insertRow(rowCount);
// var cell1 = row.insertCell(0);
// var element1 = document.createElement("input");
// cell1.appendChild(element1);
// var cell2 = row.insertCell(1);
// cell2.innerHTML = rowCount + 1;
// var cell3 = row.insertCell(2);
// var element2 = document.createElement("input");
// cell3.appendChild(element2);
// var cell4 = row.insertCell(2);
// var element3 = document.createElement("input");
// cell4.appendChild(element2);
//and then add the value to the dynamic row
// $(cell1).append(thisItem());
// $(cell2).append(thisAmount());
// $(cell3).append(thisCost());
// $(cell4).append(myTotal);
};
//is this where the value
function calculate() {
var myAmount = "td".getElementById("amount").value;
var myPrice = "td".getElementById("price").value;
var result = "td".getElementById("result");
var myResult = myAmount * myPrice;
("#result").html() = myResult;
}
function calculate2() {
var itemTotal = []
for (i = 0; i < itemTotal; i++) {
//need a function that gets all the values of the result
//td to push to the array
itemTotal.push();
}
///int sum = IntStream.of(itemTotal).sum();
}
//end of the Function where you CLICK}
});
//Maybe we needed to use objects
//added items - this needs to append the table
/*function itemAdded (item, amount, price){
this.item = name;
this.amount = amount;
this.price = price;
}
var newItem = new itemAdded("Ratan Chair",2, 35)
//is this where the value is
this.total = function() {
itemAdded(amount)*itemAdded(price)
console.log(newItem.total())
};
//is this where the value is calculated - but we have above
function calculate() {
var myAmount = "td".getElementById("amount").value;
var myPrice = "td".getElementById("price").value;
var result = "td".getElementById("result");
var myResult = myAmount * myPrice;
("#result").html() = myResult;
}
function calculate2() {
var itemTotal = []
for (1 = 0; i < itemTotal; i++)
//need a function that gets all the values of the result
//td to push to the array
itemTotal.push();
int sum = IntStream.of(itemTotal).sum();
};*/
//mouse over and see the cart
$("#viewCart").mouseover(function(){
$("#sidebar").fadeIn("fast");
});
$("#viewCart").mouseleave(function(){
$("#sidebar").fadeOut("fast");
});
//end of docready
});