Sure. It's not really different from our other operations of finding things, as we did with buttons and such:
Then, in JS, we do:
Here, we have a form element:
So the JS part is like this:
The latter code is hidden inside our generic form handler.
Good question. Let's expand the previous code:
So the callback does the custom stuff for this form. In this case, it uses the Truck's createOrder method.
Yes, it can be anything we want. It's how we hook into that form submission, so that we can do some custom processing.
Wow, are you taking CS 304 instead? Great question, but outside the scope of CS 204. I'll say a few things here, but please follow up by email or in office hours if you'd like to learn more.
To upload files, we have to (1) use a different encoding type
(enctype) of form, and (2) a different input
(type=file) which creates a file selection widget in the
browser. The user can then select the file to upload, so hopefully,
they don't compromise their own security. Once the file is uploaded,
the back end needs to make sure things are stored securely on the
server.
Great!