28 lines
788 B
JavaScript
28 lines
788 B
JavaScript
import { Trip, Trips } from './lib_trips.js';
|
|
|
|
$(document).ready( () => {
|
|
const trips = new Trips();
|
|
|
|
$("#add_trip").click( () => {
|
|
const trip = new Trip(
|
|
$("#destination").val(), $("#miles").val(), $("#gallons").val() );
|
|
|
|
if (trip.isValid) {
|
|
trips.push(trip);
|
|
$("#trip_list").val(trips.toString());
|
|
|
|
$("#destination").val("");
|
|
$("#miles").val("");
|
|
$("#gallons").val("");
|
|
|
|
$("#destination").focus();
|
|
}
|
|
else {
|
|
alert("Please complete all fields.\nMiles and gallons "
|
|
+ "must be numeric and greater than zero.");
|
|
$("#destination").select();
|
|
}
|
|
});
|
|
|
|
$("#destination").focus();
|
|
}); |