-
Notifications
You must be signed in to change notification settings - Fork 0
/
myScript.js
186 lines (147 loc) · 4.87 KB
/
myScript.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
var p1 = 0, p2 = 0, p3=0, p4=0, p5=0, p6=0, p7=0, p8=0, p9=0, p10=0;
function price1(){
var x = document.getElementById("unit1");
var selected = x.options[x.selectedIndex].value;
var y = document.querySelector('input[name="type1"]:checked').value;
var myPrice = y * selected;
p1= myPrice;
document.getElementById("price1").innerHTML =myPrice;
}
function price2(){
var x = document.getElementById("unit2");
var selected = x.options[x.selectedIndex].value;
var y = document.querySelector('input[name="type2"]:checked').value;
var myPrice = y * selected;
p2= myPrice;
document.getElementById("price2").innerHTML =myPrice;
}
function price3(){
var x = document.getElementById("unit3");
var selected = x.options[x.selectedIndex].value;
var y = document.querySelector('input[name="type3"]:checked').value;
var myPrice = y * selected;
p3= myPrice;
document.getElementById("price3").innerHTML =myPrice;
}
function price4(){
var x = document.getElementById("unit4");
var selected = x.options[x.selectedIndex].value;
var y = document.querySelector('input[name="type4"]:checked').value;
var myPrice = y * selected;
p4= myPrice;
document.getElementById("price4").innerHTML =myPrice;
}
function price5(){
var x = document.getElementById("unit5");
var selected = x.options[x.selectedIndex].value;
var y = document.querySelector('input[name="type5"]:checked').value;
var myPrice = y * selected;
p5= myPrice;
document.getElementById("price5").innerHTML =myPrice;
}
function price6(){
var x = document.getElementById("unit6");
var selected = x.options[x.selectedIndex].value;
var y = document.querySelector('input[name="type6"]:checked').value;
var myPrice = y * selected;
p6= myPrice;
document.getElementById("price6").innerHTML =myPrice;
}
function price7(){
var x = document.getElementById("unit7");
var selected = x.options[x.selectedIndex].value;
var y = document.querySelector('input[name="type7"]:checked').value;
var myPrice = y * selected;
p7= myPrice;
document.getElementById("price7").innerHTML =myPrice;
}
function price8(){
var x = document.getElementById("unit8");
var selected = x.options[x.selectedIndex].value;
var y = document.querySelector('input[name="type8"]:checked').value;
var myPrice = y * selected;
p8= myPrice;
document.getElementById("price8").innerHTML =myPrice;
}
function price9(){
var x = document.getElementById("unit9");
var selected = x.options[x.selectedIndex].value;
var y = document.querySelector('input[name="type9"]:checked').value;
var myPrice = y * selected;
p9= myPrice;
document.getElementById("price9").innerHTML =myPrice;
}
function price10(){
var x = document.getElementById("unit10");
var selected = x.options[x.selectedIndex].value;
var y = document.querySelector('input[name="type10"]:checked').value;
var myPrice = y * selected;
p10= myPrice;
document.getElementById("price10").innerHTML =myPrice;
}
function calculation() {
var discount=0.0;
if(document.getElementById("items1").checked != true)
p1 = 0;
else if(document.getElementById("items2").checked != true)
p2 = 0;
else if(document.getElementById("items3").checked != true)
p3 = 0;
else if(document.getElementById("items4").checked != true)
p4 = 0;
else if(document.getElementById("items5").checked != true)
p5 = 0;
else if(document.getElementById("items6").checked != true)
p6 = 0;
else if(document.getElementById("items7").checked != true)
p7 = 0;
else if(document.getElementById("items8").checked != true)
p8 = 0;
else if(document.getElementById("items9").checked != true)
p9 = 0;
else (document.getElementById("items10").checked != true)
p10 = 0;
var total = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
if(total > 500){
discount = 0.15*total;
}
var afterTax = total - discount;
document.getElementById("total").innerHTML ="Total: "+total+"<br>After tax: "+afterTax;
var txt;
var r = confirm("Do you want to proced with the payment? ");
if (r == true) {
txt = "Thank you!";
} else {
txt = "application withdraw!";
}
document.getElementById("text").innerHTML = txt;
}
function validateForm() {
//var emailMatch = /^\[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[A-Z]{2,4}$/
var fname = document.forms["myForm"]["fname"].value
var lname = document.forms["myForm"]["lastname1"].value
var email = document.forms["myForm"]["email"].value
errors = []
if(!fname){
errors.push("The first name is required")
}
if(!lname){
errors.push("The last name is required")
}
if(!email){
errors.push("the email field is required")
}
/*
else if(!emailMatch.test(email)){
errors.push(email)
errors.push("the email has to be in the format of [email protected]")
}
*/
if(errors.length){
event.preventDefault()
alert(errors.join("\n"))
}
else{
prompt("Are you sure you want to submit")
}
}