-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
251 lines (237 loc) · 10.4 KB
/
index.html
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<!doctype html>
<html lang="en">
<head>
<title>Welcome to Shopping Cart</title>
</head>
<body>
<link type="text/css" rel="stylesheet" href="css/style.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
<h2>Add Products</h2>
<div class="checkboxes">
Orencia:
<input name="Orencia" type="checkbox" value="Orencia" id="Orencia" /> Opdivo:
<input name="Opdivo" type="checkbox" value="Opdivo" id="Opdivo" /> Sprycel:
<input name="Sprycel" type="checkbox" value="Sprycel" id="Sprycel" /> Eliquis:
<input name="Eliquis" type="checkbox" value="Eliquis" id="Eliquis" />
<button type="button" class="btn btn-success btn-lg pull-right" data-toggle="modal" href="#myModal2">Checkout</button>
</div>
<div class="wrap">
<div class="Orencia">
<h4>Product 1
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-book-id="Product 1" href="#myModal">Add to cart</button>
</h4>
</div>
<div class="Orencia">
<h4>Product 2
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-book-id="Product 2" href="#myModal">Add to cart</button>
</h4>
</div>
<div class="Orencia">
<h4>Product 3
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-book-id="Product 3" href="#myModal">Add to cart</button>
</h4>
</div>
<div class="Opdivo">
<h4>Product 4
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-book-id="Product 4" href="#myModal">Add to cart</button>
</h4>
</div>
<div class="Opdivo">
<h4>Product 5
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-book-id="Product 5" href="#myModal">Add to cart</button>
</h4>
</div>
<div class="Opdivo">
<h4>Product 6
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-book-id="Product 6" href="#myModal">Add to cart</button>
</h4>
</div>
<div class="Sprycel">
<h4>Product 7
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-book-id="Product 7" href="#myModal">Add to cart</button>
</h4>
</div>
<div class="Sprycel">
<h4>Product 8
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-book-id="Product 8" href="#myModal">Add to cart</button>
</h4>
</div>
<div class="Eliquis">
<h4>Product 9
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-book-id="Product 9" href="#myModal">Add to cart</button>
</h4>
</div>
<div class="Eliquis">
<h4>Product 10
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-book-id="Product 10" href="#myModal">Add to cart</button>
</h4>
</div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="myModalTitle"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h5 class="modal-body" id="myModalBody"></h5>
Quantity:
<input type="number" name="quantity" id="quantity" min="1" max="50">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" id="btnSave" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<div class="modal" id="myModal2">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Cart Items</h4>
</div>
<div class="modal-body">
<p>Selected items are</p>
<div id="myModalBody2"></div>
<div class="row">
<div class="col-md-4">
<p1>First name:
<input type="text" id="fname" onkeyup="myFunction(id)" name="fname">
</p1>
<div id="fnameError" class="text-danger"></div>
</div>
<div class="col-md-4">
<p2>Last name:
<input type="text" id="lname" onkeyup="myFunction(id)" name="lname">
</p2>
<div id="lnameError" class="text-danger"></div>
</div>
<div class="col-md-4">
<p3>Address:
<input type="text" id="address" onkeyup="myFunction(id)" name="address">
</p3>
<div id="addrError" class="text-danger"></div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="btnSubmit" class="btn btn-success" data-toggle="modal" href="#lost">Submit</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<script>
var array = [];
var fname;
var lname;
var address;
$('input[type="checkbox"]').click(function () {
if ($('input[type="checkbox"]:checked').length > 0) {
$('.wrap > div').hide();
$('input[type="checkbox"]:checked').each(function () {
$('.wrap >div[class=' + this.id + ']').show();
});
} else {
$('.wrap > div').show();
}
});
$('#myModal').on('show.bs.modal', function (e) {
var title = $(e.relatedTarget).data('book-id');
$("#myModalTitle").text(title);
$("#myModalBody").text(title);
});
$(function () {
$('#myModal').on('click', '#btnSave', function (e) {
var item = {};
var name = $('#myModalBody').text();
//var name = document.getElementById("myModalBody").innerText ;
var quantity = $('[id=quantity]').val();
$('[id=quantity]').val(0);
item.name = name;
item.quantity = quantity;
array.push(item);
localStorage.setItem("array", JSON.stringify(array));
$('#myModal').modal('hide');
});
});
$('#myModal2').on('show.bs.modal', function (e) {
var i;
array = [];
array = JSON.parse(localStorage.getItem("array"));
$('#myModalBody2').empty();
//document.getElementById('myModalBody2').innerHTML="";
for (i = 0; i < array.length; i++) {
$("#myModalBody2").append(array[i].name + ":" + array[i].quantity + '<br>')
}
});
function myFunction(id) {
fname = $('#fname').val();
lname = $('#lname').val();
address = $('#address').val();
var name_regex = /^[a-zA-Z]+$/;
var add_regex = /^[0-9a-zA-Z]+$/;
if (id == "fname") {
if (!fname.match(name_regex)) {
$('#fnameError').text("Please give only alphabets for First name");
} else {
$('#fnameError').text("");
}
}
if (id == "lname") {
if (!lname.match(name_regex)) {
$('#lnameError').text("Please give only alphabets for Last name");
} else {
$('#lnameError').text("");
}
}
if (id == "address") {
if (!address.match(add_regex)) {
$('#addrError').text("Please give correct address");
}
else {
$('#addrError').text("");
}
}
}
$(function () {
$('#myModal2').on('click', '#btnSubmit', function (e) {
fname = $('#fname').val();
lname = $('#lname').val();
address = $('#address').val();
var firstNameEmpty = false;
var lastNameEmpty = false;
var addressEmpty = false;
if (fname.length == 0) {
$('#fnameError').text("*Name cannot to empty"); // This Segment Displays The Validation Rule For Name
$("#fname").focus();
firstNameEmpty = true;
}
if (lname.length == 0) {
$('#lnameError').text("*Last name cannot to empty");
$("#lname").focus();
lastNameEmpty = true;
}
if (address.length == 0) {
$('#addrError').text("*Address cannot be empty");
$("#address").focus();
addressEmpty = true;
}
if (!firstNameEmpty && !lastNameEmpty && !addressEmpty) {
alert("Your order has been placed successfully");
$('#myModal2').modal('hide');
}
});
});
</script>