Build a Group Travel Enquiry Form with HTML and JavaScript
A travel enquiry form needs more than a name and a phone number. For group journeys, an operator also needs the passenger count, travel dates, pickup location and destination. Without those details, the first response o
A travel enquiry form needs more than a name and a phone number. For group journeys, an operator also needs the passenger count, travel dates, pickup location and destination.
Without those details, the first response often becomes another round of questions.
This tutorial builds a small enquiry preview using semantic HTML and JavaScript. The example is based on the requirements of a group travel business such as Urbania Ahmedabad. It is an illustrative prototype, not a description of that websiteβs implementation.
1. Separate an enquiry from a confirmed booking
Submitting travel details does not automatically confirm a vehicle, price or reservation.
Use wording that matches what the interface actually does:
- Preview enquiry when showing entered details.
- Request a quote when sending a request to an operator.
- Booking confirmed only after the booking process has genuinely completed.
Our example previews information in the browser. It does not send or save enquiries.
2. Start with labelled HTML fields
Use visible labels rather than relying on placeholder text. Add appropriate input types and native constraints for required information.
<form id="travel-enquiry" aria-describedby="demo-note">
<p id="demo-note">
Demo: preview your trip details. Nothing is sent or saved.
</p>
<p>
<label for="pickup">Pickup location</label>
<input
id="pickup"
name="pickup"
type="text"
maxlength="200"
required
>
</p>
<p>
<label for="destination">Destination</label>
<input
id="destination"
name="destination"
type="text"
maxlength="200"
required
>
</p>
<p>
<label for="departure">Departure date</label>
<input
id="departure"
name="departure"
type="date"
required
>
</p>
<p>
<label for="return-date">Return date</label>
<input
id="return-date"
name="returnDate"
type="date"
required
>
</p>
<p>
<label for="passengers">Number of passengers</label>
<input
id="passengers"
name="passengers"
type="number"
min="1"
step="1"
required
>
</p>
<button type="submit">Preview enquiry</button>
</form>
<p id="enquiry-preview" role="status"></p>
The passenger field describes the group size. It does not promise that one vehicle can accommodate that number.
In a production form, explain whether children should be included and collect any relevant luggage requirements.
3. Validate the relationship between dates
HTML can require both dates, but we also need to check that the return date is not earlier than departure.
Place this script after the HTML:
const form = document.querySelector("#travel-enquiry");
const departure = document.querySelector("#departure");
const returnDate = document.querySelector("#return-date");
const preview = document.querySelector("#enquiry-preview");
function validateDates() {
const invalidOrder =
departure.value &&
returnDate.value &&
returnDate.value < departure.value;
returnDate.setCustomValidity(
invalidOrder
? "Return date must be on or after departure."
: ""
);
}
form.addEventListener("input", () => {
validateDates();
preview.textContent = "";
});
form.addEventListener("submit", (event) => {
event.preventDefault();
validateDates();
if (!form.reportValidity()) {
return;
}
const values = new FormData(form);
const pickup = values.get("pickup").trim();
const destination = values.get("destination").trim();
if (!pickup || !destination) {
preview.textContent =
"Enter a pickup location and destination, not just spaces.";
return;
}
preview.textContent =
`${values.get("passengers")} passengers: ` +
`${pickup} to ${destination}. ` +
`Departure: ${values.get("departure")}. ` +
`Return: ${values.get("returnDate")}. ` +
"Preview onlyβno enquiry has been submitted.";
});
Date inputs expose their values in YYYY-MM-DD format. Comparing these populated values lets us check their chronological order without converting them into localised display strings.
Clear the custom validity message when the dates become valid again. Otherwise, an earlier error can continue blocking submission.
4. Render user input as text
The preview uses textContent rather than inserting user input through innerHTML.
A pickup address should appear as text, even if someone enters characters that resemble HTML.
The status region also allows assistive technology to announce the updated preview without moving keyboard focus.
5. Add real submission deliberately
Before turning this prototype into a live enquiry form:
- Connect it to a server endpoint.
- Validate all submitted values again on the server.
- Add contact fields with appropriate labels and autocomplete.
- Handle network failures without clearing the visitorβs entries.
- Display success only after the server confirms receipt.
- Explain how enquiry information will be used.
Browser validation helps visitors correct mistakes. It does not replace server-side checks.
6. Check the important interactions
Try these cases before publishing:
- Leave a required field empty.
- Enter zero passengers.
- Select a return date before departure.
- Correct the dates after seeing an error.
- Enter spaces as the pickup location.
- Complete the form using only the keyboard.
- Preview it on a narrow mobile screen.
A useful enquiry form collects enough information for the next conversation while keeping its actions and messages accurate.
Further reading
MDN: Client-side form validation
Disclosure: This article, code example and cover image were created with AI assistance.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.