-
Notifications
You must be signed in to change notification settings - Fork 2
AI‐12
Saúl Castillo edited this page Sep 24, 2024
·
2 revisions
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
h2element, 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 aSubmittext.
- Add an
- After the previous
Leave a Messagesection, 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
messageFormthat uses DOM Selection to select the "leave_message" form by name attribute. - Add an event listener to the messageForm element that handles the
submitevent. - 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
messageSectionand use DOM Selection to select the messages section by id. - Create a variable named
messageListand use DOM Selection to query themessageSection(instead of the entire document) to find the<ul>element. - Create a variable named
newMessagethat makes a new list item<li>element. - Set the inner HTML of your
newMessageelement with the following information: An<a>element that displays theusersNameand is a clickable link to theusersEmail(hint: use the mailto: prefix). A<span>element that displays theusersMessage. - Create a variable named
removeButtonthat 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
removeButtonbutton that handles theclickevent. - Inside the
removeButtoncallback function: Create a variable namedentrythat finds the button's parent element using DOM Traversal and remove theentryelement from the DOM. - Append the
removeButtonto thenewMessageelement. - Append the
newMessageto themessageListelement
- As a stretch goal (optional):
- Hide the
Messagessection, including the Messages header, when the list is empty. - Create an
editbutton for each message entry that allows the user to input a new/modified message
- Hide the