-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
73 lines (71 loc) · 3.55 KB
/
script.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
function submitForm(event) {
event.preventDefault();
const category = document.getElementById('category').value;
const timing = document.getElementById('timing').value;
const availableSeat = document.getElementById('availableSeat').value;
const name = document.getElementById('name').value;
const bookingDate = document.getElementById('bookingDate').value;
const seatType = document.getElementById('seatType').value;
document.getElementById('categoryDisplay').textContent = `Category: ${category}`;
document.getElementById('timingDisplay').textContent = `Timing: ${timing}`;
document.getElementById('availableSeatDisplay').textContent = `Available Seat: ${availableSeat}`;
document.getElementById('nameDisplay').textContent = `Name: ${name}`;
document.getElementById('bookingDateDisplay').textContent = `Booking Date: ${bookingDate}`;
document.getElementById('seatTypeDisplay').textContent = `Seat Type: ${seatType}`;
document.getElementById('successMessage').textContent = 'Booking Successful!';
document.getElementById('bookingDetails').classList.remove('hidden');
document.getElementById('downloadTicketBtn').classList.remove('hidden');
document.getElementById('downloadTicketBtn').onclick = downloadTicket;
}
function downloadTicket() {
const category = document.getElementById('category').value;
const timing = document.getElementById('timing').value;
const availableSeat = document.getElementById('availableSeat').value;
const name = document.getElementById('name').value;
const bookingDate = document.getElementById('bookingDate').value;
const seatType = document.getElementById('seatType').value;
const ticketContent = `Category: ${category}\nTiming:
${timing}\nAvailable Seat:
${availableSeat}\nName:
${name}\nBooking Date:
${bookingDate}\nSeat Type:
${seatType}`;
const blob = new Blob([ticketContent], { type: 'text/plain' });
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = 'ticket.txt';
link.click();
}
function changeSeatType() {
const category = document.getElementById('category').value;
const seatTypeSelect = document.getElementById('seatType');
seatTypeSelect.innerHTML = '';
// Select the availableSeat dropdown element
const availableSeatSelect =document.getElementById('availableSeat');
// Clear the options
availableSeatSelect.innerHTML = '';
if (category === 'bus' || category === 'train') {
const seatOptions = ['General', 'Sleeper', 'AC'];
seatOptions.forEach(option => {
const optionElement = document.createElement('option');
optionElement.value = option.toLowerCase();
optionElement.textContent = option;
seatTypeSelect.appendChild(optionElement);
});
} else if (category === 'movie') {
const seatOptions = ['Standard', 'Premium', 'VIP'];
seatOptions.forEach(option => {
const optionElement = document.createElement('option');
optionElement.value = option.toLowerCase();
optionElement.textContent = option;
seatTypeSelect.appendChild(optionElement);
});
}
for (let i = 1; i <= 30; i++) {
const optionElement = document.createElement('option');
optionElement.value = i;
optionElement.textContent = i;
availableSeatSelect.appendChild(optionElement);
}
}
window.onload = changeSeatType;