-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab9.html
122 lines (105 loc) · 3.35 KB
/
lab9.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lab 9 - before Mid</title>
<style type="text/css">
input[type='text']{
margin: 10px;
}
input{
margin-left: 10px;
margin-top: 10px;
}
div.error{
color: red;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div>
<div class="error"></div>
<form method="post" action="#" id="bookingForm">
<label>Name</label>
<input type="text" id="name"><br/>
<label>Street</label>
<input type="text" id="street" ><br/>
<label>State</label>
<select id="state" >
<option value="">Select One</option>
<option value="iowa">IOWA</option>
<option value="ny">NY</option>
</select>
<br/>
<label>Zip Code</label>
<input type="number" id="zipcode" ><br/>
<label>How many seats?</label>
<input type="number" id="seats" value="1" ><br/>
<fieldset>
<legend>Which taxi do you require?</legend>
<input type="radio" name="cartype" value="car">CAR <br/>
<input type="radio" name="cartype" value="van">VAN <br/>
<input type="radio" name="cartype" value="tuktuk">TUK TUK <br/>
</fieldset>
<fieldset>
<legend>Extras</legend>
<input type="checkbox" name="extra" value="babyseat">Baby Seat <br/>
<input type="checkbox" name="extra" value="wheelchair">WheelChair Access <br/>
<input type="checkbox" name="extra" value="tip">Stock Tip <br/>
</fieldset>
<label>Special Instructions</label>
<textarea id="special" rows="3" cols="20">
</textarea>
<br/>
<input type="submit" id="btnSubmit" value="Submit Booking">
</form>
</div>
<script>
$(document).ready(function() {
//any code
});
$('#bookingForm').submit(function (evt){
evt.preventDefault();
let error = $('.error')[0];
error = $(error);
error.html('');
let valid=true;
if(!$('#name').val()) {
error.append('Name cannot be empty.<br>');
valid = false
}
if(!$('#street').val()) {
error.append('Street cannot be empty.<br>');
valid = false
}
if(!$('#state').val()) {
error.append('Please select State.<br>');
valid = false
}
if(!$('#zipcode').val()) {
error.append('Zip Code cannot be empty.<br>');
valid = false
}
if(!$('#seats').val()) {
error.append('Seats cannot be empty.<br>');
valid = false
}else if($('#seats').val()>200){
error.append('You can choose Max 200 Seats at a time.<br>');
valid = false
}
if(!$(':radio:checked').val()) {
error.append('Please select Car Type.<br>');
valid = false
}
if(!$(':checkbox:checked').val()) {
error.append('Please select Extra.<br>');
valid = false
}
if(valid){
this.submit();
}
});
</script>
</body>
</html>