AI‐12 - Code-the-Dream-School/intro-to-programming-2025 GitHub Wiki
On the index.html
file:
- Above the
<footer>
element, add an empty<section>
element that contains: A<h2>
header that saysLeave a Message
. - After the previous
h2
element, create an HTML<form>
element with a name attribute that equalsleave_message
. Inside this form element:- Add an
<input>
element with attributes: type set totext
, name set tousersName
, and required set to true. - Add an
<input>
element with attributes: type set toemail
, name set tousersEmail
, and required set to true. - Add a
<textarea>
element with attributes: name set tousersMessage
, and required set to true. - Each of the previous form field should also have a corresponding
<label
> element. - As a stretch goal (optional): Use
<br>
elements to stack the form fields - Add a
<button>
element with attributes: type set tosubmit
. This button should have aSubmit
text.
- Add an
- After the previous
Leave a Message
section, create a new<section>
element that contains: A<h2>
header that saysMessages
. The section should have an id attribute equal to "Messages". After the heading, add an empty unordered list<ul>
element - Add a link in your
<nav>
section that takes the user to the 'Leave a Message' section when clicked.
On the index.css
file:
- Style your leave a message form fields and buttons keeping in mind: adequate specing and appropriate sizing.
- Remember appropriate sizing in media queries too for the Leave a Message form fields and buttons.
On the index.js
file:
- On the bottom of your file, create a variable named
messageForm
that uses DOM Selection to select the "leave_message" form by name attribute. - Add an event listener to the messageForm element that handles the
submit
event. - Inside the callback function:
- Add a new line to prevent the default refreshing behavior of the "submit" event.
- Create three new variables (one for each of the three form fields) and retrieve the value from the event.
- Add a console.log statement to log the three variables you created in the previous step.
- Add a new line of code to clear the form.
- Create a variable named
messageSection
and use DOM Selection to select the messages section by id. - Create a variable named
messageList
and use DOM Selection to query themessageSection
(instead of the entire document) to find the<ul>
element. - Create a variable named
newMessage
that makes a new list item<li>
element. - Set the inner HTML of your
newMessage
element with the following information: An<a>
element that displays theusersName
and is a clickable link to theusersEmail
(hint: use the mailto: prefix). A<span>
element that displays theusersMessage
. - Create a variable named
removeButton
that makes a new<button
> element: This button should have an inner text set toremove
, a type attribute set tobutton
. - Add an event listener to the
removeButton
button that handles theclick
event. - Inside the
removeButton
callback function: Create a variable namedentry
that finds the button's parent element using DOM Traversal and remove theentry
element from the DOM. - Append the
removeButton
to thenewMessage
element. - Append the
newMessage
to themessageList
element
- As a stretch goal (optional):
- Hide the
Messages
section, including the Messages header, when the list is empty. - Create an
edit
button for each message entry that allows the user to input a new/modified message
- Hide the