
1f0a7c89ef8f7c695a8a53f6123c3960.ppt
- Количество слайдов: 17
WHAT IS A COOKIE? A cookie is a variable that is stored on the visitor's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With Java. Script, you can both create and retrieve cookie values. Examples of cookies: Name cookie - The first time a visitor arrives to your web page, he or she must fill in her/his name. The name is then stored in a cookie. Next time the visitor arrives at your page, he or she could get a welcome message like "Welcome John Doe!" The name is retrieved from the stored cookie Password cookie - The first time a visitor arrives to your web page, he or she must fill in a password. The password is then stored in a cookie. Next time the visitor arrives at your page, the password is retrieved from the cookie Date cookie - The first time a visitor arrives to your web page, the current date is stored in a cookie. Next time the visitor arrives at your page, he or she could get a message like "Your last visit was on Tuesday August 11, 2005!" The date is retrieved from the stored cookie
CREATE AND STORE A COOKIE function set. Cookie(c_name, value, exdays) { var exdate=new Date(); exdate. set. Date(exdate. get. Date() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate. to. UTCString()); document. cookie=c_name + "=" + c_value; }
RETURN A COOKIE function get. Cookie(c_name) { var i, x, y, ARRcookies=document. cookie. split("; "); for (i=0; i
CHECK COOKIE function check. Cookie() { var username=get. Cookie("username"); if (username!=null && username!="") { alert("Welcome again " + username); } else { username=prompt("Please enter your name: ", ""); if (username!=null && username!="") { set. Cookie("username", username, 365); } } }
JAVASCRIPT FORM VALIDATION Java. Script can be used to validate data in HTML forms before sending off the content to a server. Form data that typically are checked by a Java. Script could be: has the user left required fields empty? has the user entered a valid e-mail address? has the user entered a valid date? has the user entered text in a numeric field?
REQUIRED FIELDS function validate. Form() { var x=document. forms["my. Form"]["fname"]. value if (x==null || x=="") { alert("First name must be filled out"); return false; } }
E-MAIL VALIDATION function validate. Form() { var x=document. forms["my. Form"]["email"]. value var atpos=x. index. Of("@"); var dotpos=x. last. Index. Of(". "); if (atpos<1 || dotpos
DATE VALIDATION function validate. Form() { var x=document. forms["my. Form"][“date"]. value var today=new Date(); if (x>today) { alert(“Date in the furture"); return false; } }
JAVASCRIPT TIMING EVENTS With Java. Script, it is possible to execute some code after a specified time-interval. This is called timing events. The two key methods that are used are: set. Timeout() - executes a code some time in the future clear. Timeout() - cancels the set. Timeout() Note: The set. Timeout() and clear. Timeout() are both methods of the HTML DOM Window object.
function time. Msg() { var t=set. Timeout("alert." src="https://present5.com/presentation/1f0a7c89ef8f7c695a8a53f6123c3960/image-14.jpg" alt="THE SETTIMEOUT() METHOD
var c=0; var timer_is_on=0; function timed. Count() {" src="https://present5.com/presentation/1f0a7c89ef8f7c695a8a53f6123c3960/image-15.jpg" alt="INFINITE LOOP
var c=0; var timer_is_on=0; function timed. Count()" src="https://present5.com/presentation/1f0a7c89ef8f7c695a8a53f6123c3960/image-16.jpg" alt="THE CLEARTIMEOUT() METHOD
CREATE YOUR OWN JAVASCRIPT OBJECTS function person(firstname, lastname, age, eyecolor) { this. firstname=firstname; this. lastname=lastname; this. age=age; this. eyecolor=eyecolor; } var my. Father=new person("John", "D", 50, "blue"); var my. Mother=new person("Sally", “D", 48, "green");