Professional Documents
Culture Documents
Week 8
Week 8
Tables
Originally intended for display of tabular data Have been extensively used for layout. Use of CSS is preferred for layout and tables for display of tabular data
Tables = excessive code (low content:code ratio) Bad for the hearing impaired: Screen readers explain every table Try to use CSS-P and <span id=></span>
Table tricks
Utilize CSS classes For alternating row colors, utilize a different class on each row (.tdyellow vs. .tdwhite)
Form Attributes
action attribute
can be a relative or absolute link When submitting forms, if you leave out the action attribute, it will submit to itself. get results in a querystring ?a=1&b=2&c=3 post results in form-data sent in HTTP headers application/x-www-form.urlencoded default Multipart/form-data used when uploading files post only!
method attribute
enctype
Standard:
Image
Link
Users might accidentally click rest when they want to actually submit You can reset a form by re-loading the page If a user wants to reset and leave, they can just leave without resetting
All radio buttons of the same group must have the same name and different values. This allows them to be mutually-exclusive There can be multiple checkboxes of the same name. They will act like a multi-select list. Therefore, checkboxes are usually better than multi-select boxes (except for large lists)
<label for=firstName>Name</label> <input type=text name=firstName id=firstName/> Used by screen readers for visually impaired Allows user to click on the label for a radio button or checkbox.
focus() method
Calling this for any form input will set the focus to it, allowing a user to type instead of clicking on the form field with the mouse Should be used on most (if not all) forms to save the user a click Can also be used after a validation error
Validation
Field formats
Phone numbers Zip codes Email addresses Social Security Numbers Credit card numbers Names, usernames whatever
User-friendly errors
Server-side
return true if you want to submit false if you dont want it to submit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Your Name Here</title> <script type="text/javascript"> function verifyFields() { if (document.getElementById("firstName").value == "") { alert("Please provide a first name"); document.getElementById("firstName").focus; return false; } } </script> </head> <body> <form onsubmit="return verifyFields()" method="get"> First Name: <input type="text" name="firstName" id="firstName" /> <input type="submit" value="submit"/> </form> </body> </html>
Regular Expressions
A formula for checking if strings match a given pattern Since all form fields are strings, this is a standard used in form validation JavaScript supports regular expressions with the / operator
alert("No match!");
document.getElementById("firstName").focus();
return false;
} }