reading-notes

201_Read_09

This is important because..

HTML Forms

Overview of module with links to related readings, tutorials, and the like.

First Web Form

At the core, a main interaction method for users and a site, program, and/or application. The inputs generated by the user can be stored, processed, manipulated to cause dynamic changes in the interface.
Various types and styles of elements exist that allow interaction with a form, these are called form controls and most can be made through the use of the <input> element.
Types include:

Form Validation is to allow only a specific format or value to be used/entered.

Before writing a single line of code, plan what the form will entail in its design and what it’ll ask from the user. Pen and paper (or pencil) are friends and tools.

Implementation

<form> is the parent / container element.
Attributes are optional, although it is recommended to include action (where to submit data input) and method (defines HTTP method used to send data; get or post).

Up next are <label>, <input>, and/or <textarea> elements.
for attribute uses id to link with form control associated with.

Data Transmission

action and method attributes inside opening <form> tag provides instructions on where and how data is sent.

Also where the name attribute defined for individual form control matters, as they provide context on what to name each piece of data being processed (name/value pairs). For more information, visit Sending form data article.

Web Form Structure

Flexibility can equal complexity; forms come in all shapes and sizes and its your job as the developer to orchestrate the most optimal, functional, and accessible structure.

Form Elements / Controls

Answers.1

  1. Why are forms so important in web development?
    • Forms allow for user interaction and data input/transmission, as well as manipulating/adding to data sets.
  2. When designing a form, what are some key things to keep in mind when it comes to user experience?
    • can be a friend / augmented with accessibility tools; to be thoughtful in design and implementation; and to not nest forms within each other.
  3. List 5 form elements and explain their importance.
    • <form> - without it, no form
    • <label> - provides context on what the are is for, usually input.
    • <fieldset> - groups related sections
    • <button> - a way for the user to interact with the form; can select from choices or be used to submit.
    • <textarea> - another form to input data, this can be a single line or a multi-line, adaptable text box.

Learn JS

Landing page for learning the essentials of the core language. Provides links for readings, tutorials, and challenges.

Events Intro

Events are changes or… well, events that happen in a system, program, application that are recognized and accounted for to allow subsequent changes to happen. When an ‘event’ occurs, the system creates a signal, which in turn provides an opportunity for an action (code) to occur (run/execute).

Many different type of events exist and can be tied to a single element, various elements, The entire HTML file, or the entire browser window. View the event index for a comprehensive list of all the types of events that may occur.

An event listener is what is used to react to events and allow changes to occur. An event handler is a function that responds from the event listener and respond in kind. This process is known as registering an event handler.

Using addEventListener()

A method appended to objects that can execute events. Parameters include what event to expect and ‘listen’ for, and a function of some sort to invoke after the event is registered. The function can be built globally and just referenced by name within the parameters, rather than built in.

Handlers can be removed just as easy as added, removeEventListener(). Can improve execution and writing efficiency, as well as allowing a button (or other element/control) to do different things depending on circumstances and environment. Likewise, one event may have multiple ‘event listeners’ / multiple handler functions executing at same time.

addEventListener() is the go-to method, but there are a few different methods such as, event handler properties (onClick or something similar after on, and then appended to a named function) and inline event handlers, which are not recommended at all and considered bad practice.

Disadvantages include, but not limited to; not being able to add multiple listeners for one event, can become unmanageable, inefficient, and easily illegible from mixing HTML and JavaScript in the same file.

Event Objects

Parameter specified in the event handler function that is inherited directly into event handlers themselves. Usual naming schemes will be, the event object then the property referencing the element the event took place. eventObject.property.

Choose a name you can easily reference inside the event handler function; e, evt, and event are most common.
The Event reference page contains a list of properties and methods available for use.

Default Behavior

Through data validation features, we as the developer, are able to plan and account for when the input is not as expected and therefore preventing the standard behavior and events.
preventDefault() is the function we’d call upon when input does not fit where we expected a certain value or other input.

Events exist far and wide outside of JavaScript; many programming languages cater to some sort of event model and each is different. Node.js and WebExtensions are two examples of many others.

Answers.2

  1. How would you describe events to a non-technical friend?
    • events are… events! things that happen and you watch, hear, read about, etc. Similar to loops?
  2. When using the addEventListener() method, what 2 arguments will you need to provide?
    • the action/event we are listening for and a (callback) function for what we want to happen afterwards.
  3. Describe the event object. Why is the target within the event object useful?
    • event objects are parameters passed into the event handler itself and provide “extra features and info”. `.target() is useful because, it references the element that the event occurred in.
  4. What is the difference between event bubbling and event capturing?
    • bubbling associates event listening and executing with nested/container elements and capturing… only with that specific element.
    • bubbling moves up from event element up to parents; capturing from parents down to nested element.
    • javaScript

HTML5 Input Types

Event Reference and Listings

Things I Want To Know More About

Event objects preventDefault() creation (loop like?)