Challenge: Movie Search
HTML inputs are cool, but it would be cooler if the data actually went somewhere when the user clicked the "Submit" button. Learn about HTML forms to create an interactive, user-driven movie search on a webpage!
Note: For the "Submit" button to work in Glitch, the project must be opened in a separate window.
Background
Web developers use HTML forms to send data from their webpages to servers. For more information about the flow of data from forms, read this article: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_and_retrieving_form_data
Instructions
For this challenge, you will create a webpage with a form. When a user submits the form, the browser will go to the IMDb Advanced Title Search page, using the data from the form to filter the results. Before starting to build the HTML page, play around with the IMDb search here: https://www.imdb.com/search/title
Notice that when you submit the form, the redirected URL reflects the data they entered. It uses query string parameters to communicate with the server. The form populates those values, and the server parses them and returns the proper results. The webpage you create in this challenge will simulate the IMDb form, but you can personalize it however you like!
Setup
- Create a new HTML page, and add the basic tags:
html
, andbody
- Add a header at the top of your page with the text "Movie Search"
The form basics
- Add a
form
element under the header - Set the
action
attribute of the form to point to https://www.imdb.com/search/title - Inside the form, create a new
p
element - Inside the new
p
element, create a "Submit" button- To do this, create an
input
element, and set itstype
attribute tosubmit
- To do this, create an
- Open your file in a web browser, and verify that clicking "Submit" will navigate to the IMDb page
Adding basic inputs
Add a "Title" input where the user can enter for a title they wish to search. Additionally, add in a "Now Playing" checkbox, so the user can choose to search only for titles which are currently in theaters.
- Inside the form, above the "Submit" button, create a
h3
element that says "Title" - Under the "Title"
h3
, add aninput
element - On the
input
, set thetype
attribute totext
, and thename
attribute to "title"- The
name
attribute determines the field on the IMDb search
- The
- Create another
h3
element that says "Now Playing" - Under the "Now Playing"
h3
, add a checkboxinput
(set thetype
attribute tocheckbox
) - On the checkbox input, set the
name
attribute to "now_playing" - On the checkbox input, set the
value
attribute to "restrict"- This way, when the checkbox is checked, it will set "now_playing=restrict"
- Open your file in a web browser, and verify that searching for some titles works properly
Adding a "Genres" dropdown
Add a dropdown with a few genres, so the user can further narrow down their search if they so choose.
- Inside the form, add another
h3
element saying "Genre" - On the next line, create a
select
element - Set the
name
attribute of theselect
to "genres" - Within the
select
element, add anoption
element that contains the text "All" - Set the
value
attribute of theoption
element to blank (""
)- This will mean that no genre is set in the search
- Create three additional
option
elements within theselect
element - For each
option
element, the text andvalue
attribute should match, and should be real genres - Open your file in a web browser, and verify that searching for some genres works properly
Adding a "Rating" radio button set
Add some radio buttons so the user can narrow down their search by rating.
- Inside the form, add another
h3
element that says "Rating" - On the next line, add a
p
element- This
p
element will be one radio button option
- This
- Inside the radio
p
element, create aninput
element withtype
"radio" - Set the
name
attribute of the radioinput
to "certificates"- Giving radio buttons the same
name
value will ensure that only one in the group is checked
- Giving radio buttons the same
- Set the
value
attribute of the radioinput
to "US:G" - Outside of the
input
, but within the radiop
element, insert the text "G" - Repeat the above steps and create radio
p
elements for "US:PG" and "US:PG-13"- Make sure all the
name
attributes are "certificates", and they contain text
- Make sure all the
- Open your file in a web browser, and verify that searching for some ratings works properly
Adding other fields
Once you have added the fields above, revisit the IMDb Advanced Title Search page. Take a look at some of the options on that form, and how they data is represented in the query string of the URL after you submit the form. Try to add some other inputs to your webpage, or you can even try to statically set some filter values using hidden inputs!
More input types
Next Steps
After completing the Movie Search Challenge, move on to the Post Challenge.