JavaScript
What Might Need To Be Validated?
- String
- Number
- Date
- Time
- Zip Code
- URL
- E-mail Address
- Credit Card
- Salary
- etc.
Validation
- Can locate one error at a time or all errors.
- Can be server-side or client-side or both.
- One good technique is to perform client-side validation
and then to have the server-side revalidate. This cuts
down on network traffic, but also maintains control
over unreliable client-side scripts or client environments.
JavaScript Uses
- Client-Side Validation
- Add Dynamic Functionality to Webpage (e.g. show running total)
- Add Dynamic Elements to Webpage (e.g. mouse rollover)
- Use Information from Browser to Enhance Presentation
- General Tip: Use JavaScript for simple tasks and
use PHP for complex tasks.
Learning JavaScript
Some Difference From PHP
- Variables are not prefixed by $
- Local variables must be declared
- Different opening and closing script tags are required
- String concatenation uses the + sign
- There is a for ... in loop instead of a foreach loop
Events
- onblur, onchange, onfocus
- onclick
- onload, onunload
- onmouseover, onmouseout
- onreset
- onsubmit
Objects
- navigator
- properties : platform, userAgent
- window
- properties: location.href, name, locationbar.visible,
menubar.visible, personalbar.visible, scrollbars.visible,
statusbar.visible, toolbar.visible, status
- methods: alert(), back(), close(), confirm(),
forward(), open(), print(), prompt()
- document
- properties : lastModified, title, URL
- methods: write() and writeln() ---
writeln() outputs a single space
after it is finished, but write() does not. To
see the difference try document.write("hi");
document.writeln("hi"); document.write("hi");
- form
- properties: name, action, method
- methods: submit(), reset()
- form elements such as select, textarea, input, button
- properties: type, value, value.length, name
- methods: focus(), blur(), select(), charAt()
Lecture Example
Laboratory
Do something interesting and non-trivial that uses JavaScript.
If you are a Montana State student, demonstrate it during
today's lab period. If you are a University of Leipzig student,
either demonstrate it during today's lab period or e-mail it to
Sebastian (loewe AT uni-leipzig.de) no later than the end of the day.