Please enable JavaScript.
Coggle requires JavaScript to display documents.
HTML (Forms (Sending Data to Webserver (Validation (Types (Client (Built…
HTML
Forms
Overview
HTML Forms are the main point of interaction with a user and website - allow users to send data to a website
Forms are made up of widgets
- text field
- buttons
- radio buttons
- select boxes
- checkboxes
-
Implementation
Start
-
<form>
is a container element and supports some specific attributes
- action => defines url where form data should be sent
- method => defines which HTTP method to send data with POST
Key Tags
<label>
,<input>
,<textarea>
Input Field with Labels example:
<div>
<label for="name">Name</label>
</div>
<div>
<label for="mail">Email</label>
<input type="email" id="mail"
name="user_mail">
</div>
-
<input>
element => most important attribute is 'type' - defines the behaviour of the input
-
<input>
is an "empty" element (self-closing, can't have children)
- e.g
<input type="text" value="default val here" />
-
<button>
element is used to send the form data
e.g.
<div>
<button type="submit">Send</button>
</div>
-
<label>
element
- Most important element for UX (user experience) of form
- To associate a lavel to an input use
for
and id
attributes
e.g
<label for="name">Name:</label>
<input type="text" id="name" name="user_name"/>
-
Structure
<form>
- Defines a form
- Can't nest form inside another form
- Can use form widgets outside form but must arrange data sending yourself
<fieldset>
- Is a convenient way to create a group of widgets that share the same purpose - for styling purposes
<legend>
- To label a fieldset element include a
<legend>
element below the opening fieldset tag
-
<legend>
describes the purpose of fieldset
e.g.
<form>
<fieldset>
<legend>Fruit Juice Size</legend>
<fieldset>
<form>
(If have radio buttons - use fieldset)
-
Common Structures
- Common practice to wrap label in
<div>
or <p>
tag - also use <h1>
and <section>
tags
-
Native Form Widgets
Attributes
Many of the elements used to define form widgets have their own attributes - the ones however common to all are
-
form
- Form element the widget is associated with
- The value must be same as
id
attribute of <form>
-
disabled
=> default false
- Boolean value to indicate if user can interact with the element
- If attribute not specified it inherits value from containing element e.g.
<fieldset>
- If no value specified in attribute - element is enabled
autofocus
=> default false
- Boolean to indicates if element should have input focus automatically when page loads
Text Input Fields
Text <input>
are basic form widgets
- All have common behaviours
1) Can be marked readonly / disabled
2) Can have placeholder
3) Constrained in size and length
4) Benefit from spell checking
A Single line text field
<input type="text" />
- Constraint => if breaks in text - taken out on SEND
-
Types
Email Address Field
<input>
tag with type "email"
- Add multiple attributes to add many comma seperated emails
Password Field
<input>
with type "password"
- This will obscure the value in the field
- Doesn't protect data on send - as its sent as plain-text (bad practice)
- To fix => send of HTTPS (encrypted)
Search Field
<input>
with type="search"
- Browser will style this - with rounded corners
- Also their values can be autocompleted across multiple pages of same site
Phone Number Field
<input>
with type = "tel"
- No constraints - applied universally
-
Multi-line Text Fields
<textarea
cols="30"
rows="10"></textarea>
- Also accepts "warp" attribute - "hard" or "soft" regarding the wrapping of the text
Drop-Down Content
-
2 Options
Selectbox
-
-
Add attribute selected
(no quotes) to option if want to be default
-
<option>
can be nested in <optgroup>
to create groups of options
<optgroup label="fruits">
<option>Banana</option>
</optgroup>
If option is set with value
attribute - that element's value is submitted with forms
- If value is omitted then the content of
option
element is used
-
Auto-Complete Box
- Can provide suggested, auto-complete values for form widgets using
<datalist>
with some <option>
elements to specify
- Data is bound to text field (<input>) using list attribute
- Once data list is affiliated with a form widget -its options are used for autocomplete
-
<datalist>
is very new and has limited browser support
- Fallback for old browsers is
<datalist id="fruitlist">
<select>
<options>
</select>
</datalist>
Checkable Items
-
-
N.B All widgets that have "name" attribute get sent on submit - even if has no value
- For check items - only sent if it is checked
- Use
<fieldset>
and <legend>
Buttons
-
2 Types
-
-
Both pretty much the same
-
<button type="submit">
is the same as
- `<input type="submit">
Advanced Widgets
Numbers
- Widget for numbers used with
<input/>
and value="number"
-
-
Sliders
Overview
-
- Created with
<input/>
and type = "range"
- Its attributes can be
min
,max
, and step
Problem
-
e.g.
var beans = document.querySelector("#beans");
var count = document.querySelector(".beancount");
count.textContent = beans.values;
beans.oninput = function(){
count.textContent = beans.value;}
-
Date + Time Picker
-
datatime-local
=> e.g
<input type="datetime-local">
- Type can also be
month
,time
or week
Set max and min:
- `<input type="date" max="2018-16-11" min="2017-06-01"/>
-
Other Widgets to know
-
Hidden Content
Can send data to server that is not displayed to user - add invisible elements to form
<input type="hidden" value="123"/>
Meters and Progress Bars
Use the <progress>
element
- e.g
<progress max="100" value="75">75/100</progress>
-
-
- If meter is in preferred range => bar is green
- If meter is in average range => bar is yellow
- If meter is in worst range => bar is red
min < - > low < - > high < - > max
- Optimum is in one of the 3 areas
-
Custom Form Widgets
Advanced => hard to do - much easier to use 3rd party
- Need Javascript to manipulate the DOM
- To manipulate the DOM - use JQuery => dedicated framework to manipulate DOM
Use Accessible Rich Internet Application (ARIA) to make custom widgets accessible
- Use
role
attribute to define what element is used for => use "role" for Javascript manipulation
-
Introduction and Basics
What is HTML?
HTML (Hypertext Markup Language) is not a programming language => is a markup language - used to tell a browser how to structure a web page
Series of elements - which you use to enclose, wrap or mark up different parts of content to appear in a different way
Anatomy
<p>Hello</p>
1st <p> is the "opening tag" and 2nd is called "closing tag" whilst the "Hello" in the middle is called the "content
:star: The whole code is called an element
Nesting
Putting elements inside other elements (make sure nested closing tag always before main closing tag)
-
-
Block Vs Inline Elements
Block
- form a visible block on the page
- appear on new line from whatever content before it
- Any content after it will be on newline
- They tend to be structural elements on page - <p>, lists, menus
- They shouldn't be nested in inline-element
Inline
- those contained in block elements and surround small part of content - not entire paragraphs
- won't cause a new line to appear
<em>
=> inline
Empty Elements
Some elements have a single tag (self-closing tag) - which means the element is embed something e.g. image tag is <img/>
Attributes
-
Attributes contain information about element that you don't want to appear in the content
- gives a name to target with CSS styles
- attributes will be in the format
name="attribute-name"
Types
-
-
-
Boolean Attributes
=> attributes without values
e.g <input type="text"
disabled/>
=> the attribute is "disabled"
Whitespace
No matter how much whitespace you use the HTML parser reduces each one down to a single space when rendering the code
- Use whitespace for readability
Special Characters
<
, >
, "
, '
and &
are the special characters
Characters are part of HTML so can't use them in HTML document directly
-
<
= <
-
>
= >
-
&
= &
-
"
= "
-
'
= &apos
-
Debugging
HTML is permissive - still runs after errors whether they are:
Tables
-
-
-
Styling
HTML method of defining info for column of data all in one place - <col>
and <colgroup>
elements are useful for styling
-
Adding Caption with <caption>
- To give a table a caption add the following:
-
<table>
<caption> Dinosaurs</caption>
</table>
Adding Structure
<thead>
,<tfoot>
,<tbody>
-
-
-
-
-
Scope
Scope attribute is added to <th>
tags to tell screenreaders what the header is a header for e.g. row/column
- Scope can also be
colgroup
or rowgroup
=> headings for multiple columns or rows
-
Tags
Advanced Text Formats
-
Quotations
- use
<blockquote>
tags - to show quotes
- Inline quotations - use the
<q>
tag
- Citations => use the
<cite>
block - not used by browsers
Abbreviations
Use <abbr>
tag
e.g <abbr title="hyper text markup">HTML</abbr>
- Hover over it will show the title
Contact
-
<address>
tag for page author
-
-
-
-
Media Content
Images
Alternative Text
Add alt
attribute for when if image can't load => good for SEO
-
-
-
CSS Background Image
Use CSS to embed images e.g
p{
background-image: url(path/to/file) }
This is easier to position than html but only for decoration
Use <img>
tag to put image on a site
-
<img>
is an empty element - no closing tag and requires a src to point to image (Url or path)
Responsive
-
Problems
Art Direction Problem => large pic on large device needs to be cropped for iPad and again for iPhone
Resolution Switching Problem => No need to embed large image if being viewed on tiny screen
- Raster image is a set number of pixels tall and wide and looks bad if width set too wide
- If width too low - waste of bandwidth - important on mobile
Fix
Resolution Switching
srcset
=> defines et of images we allow browser to choose between.
Syntax : <image> 480w
- image width in pixels
Sizes - sets screen media conditions and shows which image is best suited
<media condition> <width of the slot image will fill>
- If browser is 480px the 440px slot is chose so the 480.png is show as its closest to 440
Can also change resolution in srcset
with X descriptors
srcset="file.png 1.5x
file-480.png 2x
- In this situation the browser works out the best resolution
Resolution Switching => different sizes depending on the device - use new attributes on image tag with srcset and sizes
<img srcset="pic.png 320w,
pic480.png 480w"
sizes = "(max-wdith: 320px) 280px,
(max-width: 480px) 440px,
800px
Art Direction
The Art Direction problem involves wanting to change the image displayed to suit different image display sizes
- Large shot will look good on desktop but bad on mobile
- Better to show cropped image
Use the <picture>
tag which fixes the problem
<picture>
<source media="(max-width:799px)" srcset="small-file1.png">
<source media="(min-width:800px)" srcset="file1.png">
<img src="file1.png" alt="text"/>
</picture>
- Source has media attribute that contains media condition - for viewport size
-
srcset
attributes contain path to image (can take multiple images)
- Must provide image
<img>
with src
and alt
or nothing will appear
Video + Audio
Video
<video>
- tag allows to embed video very easily
e.g
<video src="/path/to/source"" controls>
<p>Comment</p>
</video>
- src => same as for image
- controls => include controls for audio + playback
- <p> tag => Fallback content if it doesn't work in the browser
In early days - the web couldn't do video in HTML - so had to use flash
- HTML5 now gives a native solution with
<video>
and <audio>
tags
Supporting Formats
-
-
-
Browsers have different codecs which are used to convert compressed sound + video into binary digits and back (not all browsers have full support)
- To get around this take out
src
in <video>
tag and put in new source tag:
e.g.
<video controls>
<source src = "file.mp4" type="video/mp4">
//type is MIME type
<source src = "file.webm" type="video/webm">
</video>
Attributes
-
-
width height
=> can set video width and height but video will maintain aspect ratio - its native width/height
-
-
-
Audio
-
Same attributes as <video>
apart from
- no width/height attribute
- No poster attribute
Embed
Types
<iframe>
For embedding other web pages - embed + object for embedding pdfs, svg and Flash
Structure
<iframe
src="link"
width="100%"
height="500"
frameborder="0" //boolean for border
allowfullscreen
sandbox //heightened security
<p>Fallback Content</p>
</frame>`
-
-
-
History Overview
Was popular in the past to use frames
to create a website - small parts of a website stored in individual HTML pages
They were embedded on master document - called frameset
- which allowed you to specify the area on the screen that each frame filled
Led to Java Applets being used to embed rich content (video) on html via <object>
and <embed>
- out of fashion now
-
Embed Object Elements
General purpose for embedding external content that include Java plugins, flash and pdf
- Not in use anymore
- No more plugins - not everyone has them and not accessible