Beruflich Dokumente
Kultur Dokumente
Basic Math Calculations Dynamic Content Manipulation Control Statement Form Validation Navigation System
Properties
Math.PI
Math.E
Math.LN2 Math.LN10 Math.LOG2E Math.LOG10E Math.SQRT2 Math.SQRT1_2
Methods
sin( r ) cos( r ) tan( r ) asin( x ) acos( x ) atan( x ) atan2( x, y ) sqrt( x ) pow( x, y ) exp( x ) log( x ) round( x ) floor( x ) ceil( x ) abs( x ) max( x, y ) max( x, y ) random( )
10
This uses the browser Document Object Model (DOM). We will focus on JavaScript as a language, not its use in the browser
slide 19
Form Validation
Before an HTML form is submitted, JavaScript can be used to provide client-side data validation This is more user-friendly for the user than server-side validation because it does not require a server round trip before giving feedback If the form is not valid, the form is not submitted until the errors are fixed
Client-Side Validation
HTTP Request HTTP Response
Web Browser
Web Server
Application Server
Database Server
JavaScript Validation
Application Validation
JavaScript data validation happens before form is submitted Server-side application validation happens after the form is submitted to the application server
function checkPass() { //Store the password field objects into variables ... var pass1 = document.getElementById('pass1'); var pass2 = document.getElementById('pass2'); //Store the Confimation Message Object ... var message = document.getElementById('confirmMessage'); //Set the colors we will be using ... var goodColor = "#66cc66"; var badColor = "#ff6666"; //Compare the values in the password field //and the confirmation field if(pass1.value == pass2.value){ //The passwords match. //Set the color to the good color and inform //the user that they have entered the correct password pass2.style.backgroundColor = goodColor; message.style.color = goodColor; message.innerHTML = "Passwords Match!" }else{ //The passwords do not match. //Set the color to the bad color and //notify the user. pass2.style.backgroundColor = badColor; message.style.color = badColor; message.innerHTML = "Passwords Do Not Match!" } }
Javascript method
41
42
Example
Function changePages(newLoc)
SelectAndGo.html