All in one place Telerik School Academy HTML, CSS and JavaScript.

Slides:



Advertisements
Similar presentations
Windows Basic and Dynamic Disk Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Advertisements

HTML Forms, GET, POST Methods Tran Anh Tuan Edit from Telerik Academy
Make swiftly iOS development Telerik Academy Telerik Academy Plus.
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Amazon S 3, App Engine Blobstore, Google Cloud Storage, Azure Blobs Svetlin Nakov Telerik Software Academy academy.telerik.com.
RPN and Shunting-yard algorithm Ivaylo Kenov Telerik Software Academy academy.telerik.com Technical Assistant
Svetlin Nakov Telerik Corporation
Shortest paths in edge-weighted digraph Krasin Georgiev Technical University of Sofia g.krasin at gmail com Assistant Professor.
Telerik Software Academy Telerik School Academy.
Asynchronous Programming with C# and WinRT
Unleash the Power of JavaScript Tooling Telerik Software Academy End-to-end JavaScript Applications.
Touch and Gestures with Xamarin Forms
Character sequences, C-strings and the C++ String class, Working with Strings Learning & Development Team Telerik Software Academy.
Hybrid or Native?! Doncho Minkov Telerik Software Academy Senior Technical Trainer
Done already for your convenience! Telerik School Academy Unity 2D Game Development.
Processing Sequences of Elements Telerik School Academy C# Fundamentals – Part 1.
With Mocha and Karma Telerik Academy Telerik Software Academy.
NoSQL Concepts, Redis, MongoDB, CouchDB
The Business Plan and the Business Model Margarita Antonova Volunteer Telerik Academy academy.telerik.com Business System Analyst Telerik Corporation.
What are ADTs, STL Intro, vector, list, queue, stack Learning & Development Team Telerik Software Academy.
Making JavaScript code by template! Learning & Development Team Telerik Software Academy.
Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training Who, What, Why?
Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com.
Web Applications in Hatch Tran Anh Tuan Edit from Telerik Academy
Learning & Development Telerik Software Academy.
Telerik Software Academy ASP.NET Web Forms.
Classical OOP in JavaScript Classes and stuff Telerik Software Academy
Optimization problems, Greedy Algorithms, Optimal Substructure and Greedy choice Learning & Development Team Telerik Software.
Using Selenium for Mobile Web Testing Powered by KendoUI Telerik QA Academy Atanas Georgiev Senior QA Engineer KendoUI Team.
NoSQL Concepts, Redis, MongoDB, CouchDB Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
New features: classes, generators, iterators, etc. Telerik Academy Plus JavaScript.Next.
Throwing and Catching Exceptions Tran Anh Tuan Edit from Telerik Software Academy
Scripting Languages.
What is a dynamic web site and how to create it? Svetlin Nakov Telerik School Academy schoolacademy.telerik.com Technical Trainer
Past, Present and Future Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
Loops, Conditional Statements, Functions Tran Anh Tuan Edit from Telerik Academy
Private/Public fields, Module, Revealing Module Learning & Development Team Telerik Software Academy.
Building Data-Driven ASP.NET Web Forms Apps Telerik Software Academy ASP.NET Web Forms.
Telerik Software Academy End-to-end JavaScript Applications.
What is a Database, MySQL Specifics Trần Anh Tuấn Edit from Telerik Software Academy
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Planning and Tracking Software Quality Yordan Dimitrov Telerik Corporation Team Leader, Team Pulse, Team Leader, Team Pulse, Telerik Corporation,
Closures, Function Scope, Nested Functions Learning & Development Team Telerik Software Academy.
What you need to know Ivaylo Kenov Telerik Corporation Telerik Academy Student.
Data binding concepts, Bindings in WinJS George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
Pavel Kolev Telerik Software Academy Senior.Net Developer and Trainer
Objects, Properties, Primitive and Reference Types Learning & Development Team Telerik Software Academy.
When and How to Refactor? Refactoring Patterns Alexander Vakrilov Telerik Corporation Senior Developer and Team Leader.
Free Training and Job for Software Engineers Svetlin Nakov, PhD Manager Technical Training Telerik Corp. Telerik Software Academy.
Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com.
Doing the Canvas the "easy way"! Learning & Development Telerik Software Academy.
The past, the present, the future Telerik School Academy HTML, CSS and JavaScript.
Subroutines in Computer Programming Telerik School Academy C# Fundamentals – Part 1.
Data Types, Primitive Types in C++, Variables – Declaration, Initialization, Scope Telerik Software Academy academy.telerik.com Learning and Development.
The past, the present, the future Learning & Development Team Telerik Software Academy.
Connecting, Queries, Best Practices Tran Anh Tuan Edit from Telerik Software Academy
Processing Sequences of Elements Telerik Software Academy C# Fundamentals – Part 2.
Telerik JavaScript Framework Telerik Software Academy Hybrid Mobile Applications.
Telerik Software Academy Databases.
Things start to get serious Telerik Software Academy JavaScript OOP.
Introduction to JavaScript
Learning & Development Mobile apps for iPhone & iPad.
Processing Matrices and Multidimensional Tables Telerik Software Academy C# Fundamentals – Part 2.
Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
Functions and Function Expressions Closures, Function Scope, Nested Functions Telerik Software Academy
Implementing Control Logic in C# Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical trainer
Inheritance, Abstraction, Encapsulation, Polymorphism Telerik Software Academy Mobile apps for iPhone & iPad.
Mocking tools for easier unit testing Telerik Software Academy High Quality Code.
What why and how? Telerik School Academy Unity 2D Game Development.
LECTURE 6 (ETCS-308) Subject teacher : Ms. Gunjan Beniwal
Presentation transcript:

All in one place Telerik School Academy HTML, CSS and JavaScript

 JavaScript Overview  JavaScript history  Usage in Web  JavaScript features  Variables, operators  Conditionals, loops  Functions  DOM API 2

Dynamic Behavior in a Web Page

 JavaScript is a scripting language developed by Netscape  Intended for a front-end, now is a full server language  Lightweight and fast  JavaScript can be:  Embedded in your HTML page  Interpreted by the Web browser  Simple and flexible  Powerful to manipulate the DOM 4

 JavaScript allows interactivity such as:  Implementing form validation  React to user actions, e.g. handle keys  Changing an image on moving mouse over it  Sections of a page appearing and disappearing  Content loading and changing dynamically  Performing complex calculations  Custom HTML controls, e.g. scrollable table  Implementing AJAX functionality 5

 Can handle events  Can read and write HTML elements and modify the DOM tree  Can validate form data  Can access / modify browser cookies  Can detect the user’s browser and OS  Can be used as object-oriented language  Can handle exceptions  Can perform asynchronous server calls (AJAX) 6

7 <html><body> var name = "Doncho Minkov"; var name = "Doncho Minkov"; var greeting = "Hello, " + name; var greeting = "Hello, " + name; alert(greeting); alert(greeting); </body></html>  Create a HTML tag, and write your JavaScript inside

Live Demo

 The JavaScript code can be placed in:  tag in the head  tag in the body  External files, linked via tag  Can be done in the head or in the body, depending on the case  JavaScript files have an extentions.js  Highly recommended  The.js files are being cached by the browser 9 </script>

 JavaScript code is executed during the page loading or when the browser fires an event  All statements are executed at page loading  Some statements just define functions that can be called later  Function calls or code can be attached as "event handlers" via tag attributes or in code  Executed when the event is fired by the browser 10

<html><head><script> function printMessage (message) { function printMessage (message) { alert(message); alert(message); }</script></head><body> <img src="logo.gif" <img src="logo.gif" onclick="printMessage('clicked!')" /> onclick="printMessage('clicked!')" /></body></html> 11

 Using external script files:  External JavaScript file: 12 <html><head> </head><body> <button onclick="printMessage('Hello from file')" <button onclick="printMessage('Hello from file')" value="Call js function from external file" /> value="Call js function from external file" /></body></html> function printMessage(message) { alert(message) alert(message)}

 Using external script files:  External JavaScript file: 13 <html><head> </head><body> <button onclick="printMessage('Hello from file')" <button onclick="printMessage('Hello from file')" value="Call js function from external file" /> value="Call js function from external file" /></body></html> function printMessage(message) { alert(message) alert(message)} The tag is always empty.

 The JavaScript syntax is similar to C# and Java  Operators ( +, *, =, !=, &&, ++, …)  Variables (typeless)  Conditional statements ( if, else )  Loops ( for, while )  Arrays ( myArray[] ) and associative arrays ( myHash['abc'] )  Functions (can return value)  Function expressions (like the C# delegates) 15

 JavaScript data types:  Numbers (integer, floating-point)  Boolean (true / false)  String type – string of characters  Arrays contain items of mixed types:  Associative arrays (hash tables): 16 var message = 'You can use both single or double quotes for strings, yet use single quotes'; var mixedArray = [1, 5.3, 'aaa']; var location = { street: '22 Al. Malinov str.', street: '22 Al. Malinov str.', city: 'Sofia', city: 'Sofia', country: 'Bulgaria' country: 'Bulgaria' }; };

 Every variable is an object  Strings have functions: 17 var name = 'Doncho Minkov'; console.log(name[7]); // shows 'M' console.log(name.substring(7,13)//shows 'Minkov' console.log(name.substr(7, 6)); //shows 'Minkov' var numbers = [1, 3, 4]; console.log (arr.length); // shows 3 arr.push(7); // appends 7 to end of array arr.unshinf(-5); //adds -5 to the head of the array console.log (arr[3]); // shows 4  Arrays have functions:

 The + operator joins strings  What is '9' + 9?  Converting string to number:  or 18 string1 = 'fat '; string2 = 'cats'; console.log(string1 + string2); // fat cats console.log('9' + 9); // 99 console.log(parseInt('9') + 9); // 18 console.log('9' * 1 + 9); // 18

 Declaring new empty array:  Declaring an array holding few elements:  Appending an element / getting the last element:  Reading the number of elements (array length):  Finding element's index in the array: 19 var arr = [] var arr = [1, 2, 3, 4, 5]; arr.push(3); var element = arr.pop(); arr.length; arr.indexOf(1);

20 <html><head> JavaScript Demo JavaScript Demo function calcSum() { function calcSum() { value1 = value1 = parseInt(document.mainForm.textBox1.value); parseInt(document.mainForm.textBox1.value); value2 = value2 = parseInt(document.mainForm.textBox2.value); parseInt(document.mainForm.textBox2.value); sum = value1 + value2; sum = value1 + value2; document.mainForm.textBoxSum.value = sum; document.mainForm.textBoxSum.value = sum; } </head>

21 <body> <input type="button" value="Process" <input type="button" value="Process" onclick="javascript: calcSum()" /> onclick="javascript: calcSum()" /> <input type="text" name="textBoxSum" <input type="text" name="textBoxSum" readonly="readonly"/> readonly="readonly"/> </body></html>

Live Demo

Greater than <= SymbolMeaning > < Less than >= Greater than or equal to Less than or equal to ==Equal != Not equal 23 unitPrice = 1.30; if (quantity > 100) { unitPrice = 1.20; unitPrice = 1.20;}

 The condition may be of Boolean or any other type: 24 var a = 0; var b = true; if (typeof(a)=='undefined' || typeof(b)=='undefined') { document.write('Variable a or b is undefined.'); document.write('Variable a or b is undefined.');} else if (!a && b) { document.write('a==0; b==true;"); document.write('a==0; b==true;"); } else { document.write("a==" + a + "; b==" + b + ";"); document.write("a==" + a + "; b==" + b + ";");}

Live Demo

 The switch statement works like in C#: 26 switch (variable) { case 1: case 1: // do something // do something break; break; case 'a': case 'a': // do something else // do something else break; break; case 3.14: case 3.14: // another code // another code break; break; default: default: // something completely different // something completely different}

Live Demo

 Like in C#  for loop  while loop  do … while loop 28 var counter; for (counter=0; counter<4; counter++) { alert(counter); alert(counter);} while (counter < 5) { alert(++counter); alert(++counter);}

Live Demo

 Code structure – splitting code into parts  Data comes in, processed, result returned 30 function average(a, b, c) { var total; var total; total = a+b+c; total = a+b+c; return total/3; return total/3;} Parameters come in here. Declaring variables is optional. Type is never declared. Value returned here.

 Functions are not required to return a value  When calling function it is not obligatory to specify all of its arguments  The function has access to all the arguments passed via arguments object 31 function sum() { var sum = 0; var sum = 0; for (var i = 0; i < arguments.length; i ++) for (var i = 0; i < arguments.length; i ++) sum += parseInt(arguments[i]); sum += parseInt(arguments[i]); return sum; return sum;} alert(sum(1, 2, 4));

Live Demo

 Every HTML element is accessible via the JavaScript DOM API  Most DOM objects can be manipulated by the programmer  The event model lets a document to react when the user does something on the page  Advantages  Create interactive pages  Updates the objects of a page without reloading it 34

 Access elements via their ID attribute  Via the name attribute  Via tag name  Returns array of descendant elements of the element " el " 35 var elem = document.getElementById("some-id") var arr = document.getElementsByName("some-name") var imgTags = el.getElementsByTagName("img")

 Once we access an element, we can read and write its attributes 36 function change(state) { var lampImg = document.getElementById("lamp"); var lampImg = document.getElementById("lamp"); lampImg.src = "lamp_" + state + ".png"; lampImg.src = "lamp_" + state + ".png"; var statusDiv = var statusDiv = document.getElementById("statusDiv"); document.getElementById("statusDiv"); statusDiv.innerHTML = "The lamp is " + state"; statusDiv.innerHTML = "The lamp is " + state";}… <img src="test_on.gif" onmouseover="change('off')" onmouseout="change('on')" /> onmouseout="change('on')" />

Live Demo

 Most of the properties are derived from the HTML attributes of the tag  E.g. id, name, href, alt, title, src, etc…  style property – allows modifying the CSS styles of the element  Corresponds to the inline style of the element  Not the properties derived from embedded or external CSS rules  Example: style.width, style.marginTop, style.backgroundImage 38

Live Demo

 className – the class attribute of the tag  innerHTML – holds all the entire HTML code inside the element  Read-only properties with information for the current element and its state  tagName, offsetWidth, offsetHeight, scrollHeight, scrollTop, nodeType, etc… 40

 We can access elements in the DOM through some tree manipulation properties:  element.childNodes  element.parentNode  element.nextSibling  element.previousSibling  element.firstChild  element.lastChild 41

 Warning: may not return what you expected due to Browser differences 42 var el = document.getElementById('div-tag'); alert (el.childNodes[0].value); alert (el.childNodes[1]. getElementsByTagName('span').id); getElementsByTagName('span').id);… test span test span </div>

Live Demo

 JavaScript can register event handlers  Events are fired by the Browser and are sent to the specified JavaScript event handler function  Can be set with HTML attributes:  Can be accessed through the DOM: 45 var img = document.getElementById("myImage"); img.addEventListener("click', imageClicked);

Live Demo

 All event handlers receive one parameter  It brings information about the event  Contains the type of the event (mouse click, key press, etc.)  Data about the location where the event has been fired (e.g. mouse coordinates)  Holds a reference to the event sender  E.g. the button that was clicked 47

 Holds information about the state of [Alt], [Ctrl] and [Shift] keys  Some browsers do not send this object, but place it in the document.event  Some of the names of the event’s object properties are browser-specific 48

 Mouse events:  onclick, onmousedown, onmouseup  onmouseover, onmouseout, onmousemove  Key events:  onkeypress, onkeydown, onkeyup  Only for input fields  Interface events:  onblur, onfocus  onscroll 49

 Form events  onchange – for input fields  onsubmit  Allows you to cancel a form submission  Useful for form validation  Miscellaneous events  onload, onunload  Allowed only for the element  Fires when all content on the page was loaded / unloaded 50

 onload event 51 <html><head> function greet() { function greet() { alert('Loaded!'); alert('Loaded!'); } </head> </body></html>

Live Demo

форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop уроци по програмиране и уеб дизайн за ученици ASP.NET MVC курс – HTML, SQL, C#,.NET, ASP.NET MVC безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge курсове и уроци по програмиране, книги – безплатно от Наков безплатен курс "Качествен програмен код" алго академия – състезателно програмиране, състезания ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET курсове и уроци по програмиране – Телерик академия курс мобилни приложения с iPhone, Android, WP7, PhoneGap free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиране