-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathticket.html
More file actions
79 lines (69 loc) · 2.78 KB
/
ticket.html
File metadata and controls
79 lines (69 loc) · 2.78 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tickets</title>
</head>
<body>
<a href="index.html">
<button>Home</button>
</a>
<button onclick="loadCSV()">Load Booking Data</button>
<h1>Tickets</h1>
<label for="resNum">Reservation Number:</label>
<input type="number" id="resNum" name="resNum" min="0001" max="9999" />
<button type="button" onclick="getTicket()">Confirm</button>
<div id="reservationDetails">
<!-- Reservation details will be shown here -->
</div>
<script>
function loadCSV() {
return fetch('reservations.csv') // Ensure the CSV file is in the same folder as your HTML
.then(response => response.text())
.then(csvText => {
return parseCSV(csvText);
})
.catch(error => {
console.error('Error loading CSV:', error);
return [];
});
}
// Function to parse the CSV text
function parseCSV(csvText) {
const rows = csvText.trim().split('\n');
const reservations = [];
// Skip the header (first row)
rows.slice(1).forEach(row => {
const columns = row.split(',');
reservations.push({
reservationNumber: columns[0],
date: columns[1],
passengers: columns[2],
destination: columns[3]
});
});
return reservations;
}
function getTicket() {
const resNum = document.getElementById('resNum').value;
loadCSV().then(reservations => {
const reservation = reservations.find(r => r.reservationNumber === resNum);
const reservationDetails = document.getElementById('reservationDetails');
// Clear previous data
reservationDetails.innerHTML = '';
if (reservation) {
// If reservation is found, display details
reservationDetails.innerHTML = `
<h2>Your Ticket</h2>
<p><strong>Reservation Number:</strong> ${reservation.reservationNumber}</p>
<p><strong>Date:</strong> ${reservation.date}</p>
<p><strong>Passengers:</strong> ${reservation.passengers}</p>
<p><strong>Destination:</strong> ${reservation.destination}</p>
`;
} else {
// If reservation is not found
reservationDetails.innerHTML = '<p>Reservation not found. Please check the reservation number and try again.</p>';
}
});
}
</script>
</body>