-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate.js
70 lines (60 loc) · 2.12 KB
/
calculate.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
function createBill(){
var index=0;
var items = ["null", "null", "null","null"];
var quantities = ["null", "null", "null","null"];
var prices = ["null", "null", "null","null"];
var e1 = document.getElementById("item1");
var itemselected1 = e1.options[e1.selectedIndex].value;
if(itemselected1!="1"){
items[index]=itemselected1;
quantities[index] = document.getElementById("q1").value;
prices[index] = document.getElementById("p1").value;
index++;
}
var e2 = document.getElementById("item2");
var itemselected2 = e2.options[e2.selectedIndex].value;
if(itemselected2!="1"){
items[index]=itemselected2;
quantities[index] = document.getElementById("q2").value;
prices[index] = document.getElementById("p2").value;
index++;
}
var e3 = document.getElementById("item3");
var itemselected3 = e3.options[e3.selectedIndex].value;
if(itemselected3!="1"){
items[index]=itemselected3;
quantities[index] = document.getElementById("q3").value;
prices[index] = document.getElementById("p3").value;
index++;
}
var fTot=0;
strt(1);
for(var i=0;i<index;i++){
document.write("<tr>");
createtbl(items[i]);
createtbl(quantities[i]);
createtbl(prices[i]);
var tot=parseInt(quantities[i])*parseInt(prices[i]);
document.write("<td>"+tot+"</td>");
fTot+=tot;
document.write("</tr>");
}
document.write("<tr><td colspan=\"3\"><strong>TOTAL</strong></td><td>"+fTot+"</td><tr>");
strt(2);
}
function createtbl(x){
document.write("<td>"+x+"</td>");
}
function strt(n){
if(n==1){
document.writeln("<h1 style=\"text-align:center;\">The Bill</h1>");
document.writeln("<table width=\"90%\" border=\"1\">");
document.writeln("<tr><th>ITEMS</th><th>QUANTITY</th><th>PRICE</th><th></th></tr>");
}
else
document.write("</table>");
}
function createTot(x,y){
var tot=parseInt(x)*parseInt(y);
document.write("<td>"+tot+"</td>");
}