-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformTest.html
288 lines (203 loc) · 10.4 KB
/
formTest.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<!DOCTYPE html>
<html lang="en">
<head>
<!--Aksthis question to get better code but ask the question to chatgpt in a better way. im fixing the way to ask but my laptops dying
Write a form for my html moving company website that
-Takes an input for the customers starting location and final location,
-for every location ask the customer if its a load or unload
-for every location ask how many bedrooms is at each location.
-Every bedroom for a customer that chooses load is an additional 30 minutes charge added to the equation.
-every hour is $150
-Add up the time it will take to complete the job and write the program.
-Every jobbs quoted hours are 3 hours minimum. So if the time it will take is less than 3 hours put a minimum quote of at least 3 hoursIf the job will take less than 3 hours, instead of showing the user the amount of hours it will actually take if the calculation is less than 3 hours
-calculates the amount of miles from the starting location to the final location
-calculates how much time it should take to drive from the starting location to the final location
-Give me an example with the google maps distance matrrix api
-also add a button under the starting location input that allows users to add an up to 5 additional destinations and will calculate the distance between each destination going chronologically starting with the starting destination and then next to the 1st additional location then to the second, 3rd 4th,and 5th and then finally ending at the final destination
-Also ask how many bedrooms at each location additional location,
-ask if each additional location is a load or unload
-If its a load add an additional 30 minutes to the total cost for each additional room at each additional location -if its an unload just add an extra hour
Put the add another locaton button between the final destination input and starting destination input.
Also dont forget to put a load or unload dropdown on the final destination input as well as ask how many bedroom on it and every other location input.
add all these questions into one
-->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Moving Cost Estimator with Multiple Locations</title>
<script>
// Initial count for additional locations
var locationCount = 1;
// Function to add more location fields
function addLocation() {
if (locationCount < 5) {
var newFieldset = document.createElement('fieldset');
newFieldset.innerHTML = '<legend>Location ' + locationCount + '</legend>' +
'<label for="location' + locationCount + '">Address:</label>' +
'<input type="text" id="location' + locationCount + '" name="location' + locationCount + '" required>' +
'<br><br>' +
'<label for="bedrooms' + locationCount + '">Number of Bedrooms:</label>' +
'<input type="number" id="bedrooms' + locationCount + '" name="bedrooms' + locationCount + '" min="0" required>' +
'<br><br>' +
'<label for="loadUnload' + locationCount + '">Load/Unload:</label>' +
'<select id="loadUnload' + locationCount + '" name="loadUnload' + locationCount + '">' +
'<option value="load">Load</option>' +
'<option value="unload">Unload</option>' +
'</select>';
var form = document.getElementById('movingForm');
form.insertBefore(newFieldset, document.getElementById('addLocBtn'));
locationCount++;
} else {
alert('You can only add up to 4 additional locations.');
}
}
// Function to calculate total cost
function calculateCost() {
// Constants
const costPerHour = 60;
const minChargeHours = 2;
const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key
// Get user input
var startingLocation = document.getElementById('startingLocation').value;
var finalLocation = document.getElementById('finalLocation').value;
var bedrooms = parseInt(document.getElementById('bedrooms').value);
// Calculate hours for bedrooms
var hoursForBedrooms = Math.max(bedrooms, minChargeHours);
// Initialize total travel time and additional time for bedrooms
var totalTravelTimeSeconds = 0;
var additionalTimeMinutes = 0;
// Build the API request URL for the final location
var locations = [finalLocation];
for (var i = 1; i < locationCount; i++) {
locations.push(document.getElementById('location' + i).value);
additionalTimeMinutes += parseInt(document.getElementById('bedrooms' + i).value) * 30;
}
var apiUrl = 'https://maps.googleapis.com/maps/api/distancematrix/json?origins=' + encodeURIComponent(startingLocation) +
'&destinations=' + encodeURIComponent(locations.join('|')) +
'&key=' + apiKey;
// Make the API request
fetch(apiUrl)
.then(response => response.json())
.then(data => {
// Extract distance and duration for the final location
var element = data.rows[0].elements[0];
totalTravelTimeSeconds += element.duration.value;
document.getElementById('results').innerHTML = 'Final Location: ' +
element.distance.text + ', ' +
element.duration.text + '<br>';
// Calculate total hours including additional time for bedrooms
var totalHours = hoursForBedrooms + Math.ceil((totalTravelTimeSeconds / 3600) + (additionalTimeMinutes / 60));
var totalCost = totalHours * costPerHour;
// Display the total cost
document.getElementById('results').innerHTML += '<br>Total Cost: $' + totalCost;
})
.catch(error => console.error('Error:', error));
}
// Prevent form from submitting
function handleForm(event) { event.preventDefault(); }
</script>
</head>
<body>
<h1>Moving Cost Estimator with Multiple Locations</h1>
<form id="movingForm" onsubmit="handleForm(event); calculateCost();">
<label for="startingLocation">Starting Location:</label>
<input type="text" id="startingLocation" name="startingLocation" required>
<br><br>
<label for="loadUnload">Load/Unload:</label>
<select id="loadUnload" name="loadUnload">
<option value="load">Load</option>
<option value="unload">Unload</option>
</select>
<br><br>
<label for="bedrooms">Number of Bedrooms:</label>
<input type="number" id="bedrooms" name="bedrooms" min="1" required>
<br><br>
<label for="finalLocation">Final Location:</label>
<input type="text" id="finalLocation" name="finalLocation" required>
<br><br>
<button type="button" id="addLocBtn" onclick="addLocation()">Add Another Location</button>
<br><br>
<input type="submit" value="Calculate Cost">
</form>
<div id="results"></div>
</body>
</html>
<!--kinda what i wanted-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Moving Company Form</title>
</head>
<body>
<h1>Moving Company Quote Form</h1>
<form id="movingForm">
<!-- Starting Location -->
<label for="startLocation">Starting Location:</label>
<input type="text" id="startLocation" name="startLocation" required>
<select name="startType">
<option value="load">Load</option>
<option value="unload">Unload</option>
</select>
<br>
Bedrooms at starting location: <input type="number" name="startBedrooms">
<br>
<!-- Additional Destinations -->
<button type="button" onclick="addDestination()">Add Another Location</button>
<div id="additionalDestinations"></div>
<!-- Final Destination -->
<label for="finalLocation">Final Destination:</label>
<input type="text" id="finalLocation" name="finalLocation" required>
<select name="finalType">
<option value="load">Load</option>
<option value="unload">Unload</option>
</select>
<br>
Bedrooms at final location: <input type="number" name="finalBedrooms">
<br>
<!-- Submit Button -->
<input type="submit" value="Get Quote">
</form>
<script>
let destinationCount = 0;
function addDestination() {
if (destinationCount < 5) {
destinationCount++;
const destinationDiv = document.createElement("div");
destinationDiv.innerHTML = `
<label for="destination${destinationCount}">Additional Destination ${destinationCount}:</label>
<input type="text" id="destination${destinationCount}" name="destination${destinationCount}" required>
<select name="destination${destinationCount}Type">
<option value="load">Load</option>
<option value="unload">Unload</option>
</select>
<br>
Bedrooms at this location: <input type="number" name="destination${destinationCount}Bedrooms">
<br>
`;
document.getElementById("additionalDestinations").appendChild(destinationDiv);
}
}
// Calculate total time and cost
document.getElementById("movingForm").addEventListener("submit", function (event) {
event.preventDefault();
const form = event.target;
const loadTimePerBedroom = 30; // minutes
const unloadExtraHour = 60; // minutes
const hourlyRate = 150; // dollars per hour
// Calculate time
let totalMinutes = 0;
// ... Add logic to calculate time based on form inputs
// Calculate cost
let totalCost = 0;
// ... Add logic to calculate cost based on form inputs
// Minimum quoted hours
if (totalMinutes < 180) {
totalMinutes = 180;
}
console.log(`Total time: ${totalMinutes} minutes`);
console.log(`Total cost: $${totalCost}`);
});
</script>
</body>
</html>