Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript Bartosz Sakowicz. JavaScript - basics JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create.

Similar presentations


Presentation on theme: "JavaScript Bartosz Sakowicz. JavaScript - basics JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create."— Presentation transcript:

1 JavaScript Bartosz Sakowicz

2 JavaScript - basics JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create cookies, and much more. JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Mozilla, Firefox, Netscape, Opera.

3 JavaScript – basics (2) JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A JavaScript is usually embedded directly into HTML pages JavaScript is an interpreted language It is free Java != JavaScript !!!

4 JavaScript - examples <!– document.write(“It is JavaScript!") //-->

5 JavaScript – examples(2) function pushbutton() { alert(“Hello!"); }

6 JavaScript – examples(3) function getname(str) { alert("Hi, "+ str+"!"); } Enter your name:

7 Inserting JavaScript 1) section (as in previous transparencies) 2)Inline scripts:.... 3) External file:

8 Hierarchy of objects

9 Basics usage of objects a) With dot (.) – the same as in C++ (preferred way) b) With usage the table of properties of object, eg: document[1] – useful with loops c) With usage of association table: document["href"]

10 Expressions & operators x=7; // variables doesn’t have type! str = “Some text"; (bool1 == true) && (bool2 == false); str = “Some" + " text"; All the operators are identical as in C++/Java.

11 Control flow statements StatementExample usage breakfor(i=1; i<5; i++) { // expressions break; } continueThe same as break. forSee break.. for..infor (i in obj) {// expressions} gotogoto label1; if..elseif(condition) {// expressions if true } else {// expressions if false } returnfunction sum(a,b) {x=a+b; return x;} while do-while while(condition) {//expressions} do { //expressions } while (condition) withwith (document) { write " Some text ";}

12 Events - onload and onUnload Events are triggered when the user enters or leaves the page. The onload event is often used to check the visitor's browser type and browser version, Events are often used to deal with cookies that should be set when a user enters or leaves a page. Eg:

13 Events - onFocus, onBlur and onChange Events are often used in combination with validation of form fields. Eg: <input type="text" size="30“ id="email" onchange="checkEmail()">;

14 Events - onSubmit Event is used to validate all form fields before submitting it. Eg: <form method="post" action="xxx.htm" onsubmit="return checkForm()">

15 Events - onMouseOver and onMouseOut Events are often used to create "animated" buttons, eg: <!-- function changeImage(i,j) { document.images[i].src = “image"+j+".gif"; }-->


Download ppt "JavaScript Bartosz Sakowicz. JavaScript - basics JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create."

Similar presentations


Ads by Google