1. Why are forms so important in web development?
Web forms are a primary interaction point between a user and a website or application. They allow users to enter and send data to a web server for storage and processing, or use that data on the client-side to update the user interface immediately. Their flexibility makes them essential for building complex structures using dedicated HTML elements and attributes.
2. When designing a form, what are some key things to keep in mind when it comes to user experience?
3. List 5 form elements and explain their importance.
<form>: This element formally defines the form and contains all other elements; it uses attributes like action and method to determine where and how data is sent.<label>: This is the most important element for accessibility, as it provides a name for form widgets that screen readers can read aloud and allows users to click the text to activate the control.<input>: A versatile element used to create most form controls; its type attribute is vital because it defines the widget’s appearance and behavior (e.g., text, email, or radio button).<fieldset>: This element is used to group related widgets that share the same purpose, providing essential structure for assistive technologies and styling.<button>: Used to allow users to submit the form data; the submit type sends the data to the location specified in the form’s action attribute.1. How would you describe events to a non-technical friend?
Events are signals fired by the browser when something significant happens on a webpage—like a user clicking a button, typing a key, or a page finishing its load. You can write code that “listens” for these signals so the website can automatically react with a specific action.
2. When using the addEventListener() method, what 2 arguments will you need to provide?
3. Describe the event object. Why is the target within the event object useful?
The event object is a parameter automatically passed to event handlers that contains extra features and information about the event. The target property within this object is a reference to the specific element the event happened on. This is useful because it allows you to dynamically manipulate the exact element the user interacted with, such as changing the color of the specific button that was clicked.
4. Event bubbling vs. Event Capturing
The primary difference between these two concepts is the direction in which the event travels through the DOM.
Event Capturing is the first phase of the event cycle; it starts at the very top of the document (the window) and “trickles down” through every parent element until it reaches the specific element that was clicked. Once that target is reached, the cycle enters the Event Bubbling phase.
During bubbling, the event “bubbles up” from the target element back toward the top of the document tree. While bubbling is the default behavior for almost all browser events—meaning a click on a button will naturally trigger click listeners on its parent containers—capturing must be explicitly turned on in your code if you want a parent to intercept an event before its children.