-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
129 lines (121 loc) · 5.95 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pemesanan Tiket Travel</title>
<style>
.body {
background-color: #00BFFF;
padding: 20px;
}
form {
background-color: #FFFFFF;
width: 400px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
h2.form-title {
text-align: center;
}
</style>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body class="body">
<form>
<h2 class="form-title">Aplikasi Pemesanan Tiket Travel</h2>
<div class="mb-3">
<label for="nama" class="form-label">Nama:</label>
<input type="name" class="form-select" id="nama" required>
<div id="nameHelp" class="form-text"></div>
</div>
<div class="mb-3">
<label for="tujuan" class="form-label">Tujuan:</label>
<select id="tujuan" class="form-select" required>
<option selected disabled>Pilih kota</option>
<option value="Jakarta">Jakarta</option>
<option value="Surabaya">Surabaya</option>
<option value="Bali">Bali</option>
<option value="Bandung">Bandung</option>
<option value="Bekasi">Bekasi</option>
<option value="Bogor">Bogor</option>
<option value="Medan">Medan</option>
<option value="Jambi">Jambi</option>
<option value="Magelang">Magelang</option>
<option value="Solo">Solo</option>
<option value="Jayapura">Jayapura</option>
</select>
</div>
<div class="mb-3">
<label for="harga-tiket" class="form-label">Harga Tiket:</label>
<input type="text" id="harga-tiket" class="form-control" required>
</div>
<div class="mb-3">
<label for="jumlah-tiket" class="form-label">Jumlah Tiket:</label>
<select id="jumlah-tiket" class="form-select" required>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
<div class="mb-3">
<label for="member" class="form-check-label">Member:</label>
<input type="checkbox" id="member" class="form-check-input" required>
</div>
<div class="mb-3">
<label for="diskon" class="form-label">Diskon:</label>
<input type="number" class="form-control" id="diskon" disabled>
</div>
<div class="mb-3">
<label for="total-harga" class="form-label">Total Harga:</label>
<input type="number" class="form-control" id="total-harga" disabled>
</div>
<button type="submit" id="submit" class="btn btn-primary d-block mx-auto">Konfirmasi</button>
</form>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
<script>
const namaPembeli = document.getElementById('nama')
const tujuanKota = document.getElementById('tujuan')
const hargaTiket = document.getElementById('harga-tiket');
const jumlahTiket = document.getElementById('jumlah-tiket');
const member = document.getElementById('member');
const diskon = document.getElementById('diskon');
const totalHarga = document.getElementById('total-harga');
hargaTiket.addEventListener('input', hitungTotalHarga);
jumlahTiket.addEventListener('input', hitungTotalHarga);
member.addEventListener('click', hitungTotalHarga);
function hitungTotalHarga() {
const harga = parseFloat(hargaTiket.value) || 0;
const jumlah = parseInt(jumlahTiket.value) || 0;
const total = harga * jumlah;
totalHarga.value = total;
diskon.value = 0
if (member.checked == true) {
diskon.value = total * 0.1;
totalHarga.value = total - diskon.value;
}
}
hitungTotalHarga()
// kalo tombol ditekan
const submit = document.getElementById('submit');
submit.addEventListener('click', function () {
if (namaPembeli.value != "" && tujuanKota.value != "Pilih kota" && hargaTiket.value != "")
alert("Pembelian berhasil!\n" +
"Nama pembeli: " + namaPembeli.value + "\n" +
"Kota tujuan: " + tujuanKota.value + "\n" +
"Jumlah tiket: " + jumlahTiket.value + "\n" +
"Total harga: " + totalHarga.value
)
});
</script>
</body>
</html>