1 Javascript Web Technology. 2 Javascript Javascript is a scripting language –There is no need to compile the code before executing JS is a client-side.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
The Web Warrior Guide to Web Design Technologies
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Tutorial 10 Programming with JavaScript
Introduction to Web Site Development Steven Emory Department of Computer Science California State University, Los Angeles Lecture 8: JavaScript I.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
JavaScript, Fourth Edition
JavaScript, Third Edition
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Programming with JavaScript (Chapter 10). XP Various things Midterm grades: Friday Winter Career Fair – Thursday, April 28, 2011 (11 am to 3 pm). – MAC.
JavaScript Part 1.
Week 9 PHP Cookies and Session Introduction to JavaScript.
2440: 211 Interactive Web Programming Expressions & Operators.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
Chapter 3: Data Types and Operators JavaScript - Introductory.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
1 Javascript Web and Database Management System. 2 Javascript Javascript is a scripting language –There is no need to compile the code before executing.
JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-
4.4 JavaScript (JS) Deitel Ch. 7, 8, 9, JavaScript & Java: Similarities JS (JavaScript) is case-sensitive Operators –arithmetic: unary +, unary.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
JavaScript Syntax, how to use it in a HTML document
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript, Fourth Edition
JavaScript History and Versions JavaScript was introduced as part of the Netscape 2.0 browser Microsoft soon released its own version called JScript ECMA.
COMP403 Web Design JAVA SCRİPTS Tolgay KARANFİLLER.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
1 JavaScript in Context. Server-Side Programming.
Java Script About Java Script Document Object Model Incorporating JavaScript Adding JavaScript to HTML Embedding a Javascript External Scripts Javascript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
LING 408/508: Programming for Linguists Lecture 11 October 5 th.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Expressions and Data Types Professor Robin Burke.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
REEM ALMOTIRI Information Technology Department Majmaah University.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
CGS 3066: Web Programming and Design Spring 2017
Chapter 6 JavaScript: Introduction to Scripting
“Under the hood”: Angry Birds Maze
Tutorial 10 Programming with JavaScript
Chapter 4 Client-Side Programming: the JavaScript Language
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript and Ajax (Expression and Operators)
JavaScript an introduction.
Web Systems Development (CSC-215)
WEB PROGRAMMING JavaScript.
T. Jumana Abu Shmais – AOU - Riyadh
Tutorial 10 Programming with JavaScript
Tutorial 10: Programming with javascript
Web Programming– UFCFB Lecture 13
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

1 Javascript Web Technology

2 Javascript Javascript is a scripting language –There is no need to compile the code before executing JS is a client-side program, which can be run on any JS- supported browser, ie. Firefox, IE, Safari, Opera, etc. JS can be embedded in the HTML file or imported from a separate JS file

3 Imported JS //Javascript inline comment window.alert("Hello World!"); hello.js JSHelloWorld.html JSHelloWorld.html

4 Embedded JS JSHelloWorld.html window.alert(“Hello World!”); JSHelloWorld.html

5 JS Input JSHelloWorld.html var inString = window.prompt(“Please enter your number”, “100”); JSInput.html

6 JS Print document.write() Javascript document.write(" Hello World!!! "); document.write(" Good Planet!!! ");

7 var rndNumber; //Number the computer randoms var guess = -1; //User's latest guess var count = 1;// Count number of guess rndNumber = Math.ceil(Math.random()*1000); while(guess!=rndNumber && count <= 10) { guess = window.prompt(count + ": Pick number between 1 and 1000.",""); if(guess<rndNumber) window.alert("Your guess of " + guess + " was too low"); else if(guess>rndNumber) window.alert("Your guess of " + guess + " was too high"); else { window.alert("Your got it! [" + rndNumber +"]"); break; } count = count + 1; //count += 1; or count++; } if(count>10) window.alert("You lost!!!");

8 Variables and Data Types Variables in JS do not have data types However, every variable has a value, and every variable belongs to one of the six JS data types: 1.Number 2.String 3.Boolean 4.Null 5.Object 6.Undefined (variable that has been declared but has not been assigned a value.

9 Values Returned by typeof Operand ValueString typeof Returns nullobject Booleanboolean Numbernumber Stringstring Native Object representing functionfunction Native Object not representing functionobject Declared variable with no valueundefined Undeclared variableundefined Nonexistent property of an Objectundefined var i; var j; j = "Not a number"; alert("i is " + (typeof i) + "\n" + "j is " + (typeof j)); i is undefined j is string

10 JS Statements Expression statement –A statement that consists entirely of an expression Block statement –A set of statements enclosed in braces { and } Keyword statement –Statements that begin with keywords such as var, if, etc. i = 5; j++; m==true; { x = 5; y = 10 area = x * y; } var i; if score < 50 window.alert(“You failed.”);

11 Some JS Keyword Statements Statement NameSyntax If-thenif (expr) stmt If-then-elseif (expr) stmt else stmt Dodo stmt while (expr) Whilewhile (expr) stmt Forfor (part1; part2; part3) stmt Continuecontinue Breakbreak Return-voidreturn Return-valuereturn expr Switchswitch (expr) { cases } Trytry try-block catch-part Throwthrow expr

12 Operators Binary Operators –Has two operands, such as: Unary Operators –Has a single operand. –A unary operator may be either prefix or postfix – –i.e. Ternary Operators –Has three operands –The conditional operator is a good example –i.e. window.alert(“You “ + (score<50)?”fail”:”pass”); a*b; x+y; ++i; i--; ~x;

13 Literals Literals are strings of characters that represent values in the language: –null = Null data type –true and false = Boolean values –Numbers can be written as integer (whole number) or decimals Scientific notation: -12.4e12 means x Hexadecimal notation: 0xfa00 Magnitude of numbers: and –String: a quoted string of characters (“xxx”) –Unicode: \u005c

14 Array Array can be created as: –Use the Array constructor with no argument –Initialize values with Array constructor –Create two-dimensional array var ary1 = new Array(); var ary2 = new Array( 4, true, “OK”); var ary3 = [ 4, true, “OK” ]; var ary2d = [ [ “X”, “0”, “0” ], [ “0”, “X”, “0” ], [ “0”, “X”, “X” ] ];

15 Functions A function in JS is composed of: –The keyword function –Identifier representing function name –List of identifiers representing formal parameter list –The statements representing function body var message = "Left"; function change(message) { message = "Right"; window.alert(message); return; } change(message); window.alert(message);

16 JS Dom The Javascript DOM DOM is "Document Object Model”. Document = the web page Object = virtual objects Model = map Javascript DOM html head metatitle body h1pul li

17 Javascript Language Hierarchy Navigator Mimetype Anchor Location Window Frame History Document AreaFormImage Language ArrayBooleanDateNumberMathString Link ButtonCheckbox HiddenOption PasswordRadioReset Select SubmitTextText Area

18 Example of HTML Code JS Dom The Javascript DOM DOM is “Document Object Model”. Go to Sun Go to CNN Go to NBC

19 Retrieving Elements document.getElementById(“ID name”) –Returns the element with reffered ID document.getElementsByTagName(“Tag name”) –Returns an array of all elements with the reffered tag.

20 The Javascript DOM DOM is "Document Object Model”. Go to Sun Go to CNN Go to NBC Retrieving Element by ID x = document.getElementById(‘list’);

21 The Javascript DOM DOM is "Document Object Model”. Go to Sun Go to CNN Go to NBC Retrieving Element by Tag Name x = document.getElementByTagName(‘li’);

22 The Javascript DOM DOM is "Document Object Model”. Go to Sun Go to CNN Go to NBC Retrieving Element by Tag Name x = document.getElementByTagName(‘li’); node = x[2];

23 The Javascript DOM DOM is "Document Object Model”. Go to Sun Go to CNN Go to NBC Retrieving Element by ID x = document.getElementById(‘list’); node = x.childNodes;

24 The Javascript DOM Go to Sun Go to CNN Go to NBC Accessing the Children x_first = document.getElementById(‘list’).firstchild; x_last = document.getElementById(‘list’).lastchild;

25 Chaining the Methods We can reach the node faster by chaining the methods The Javascript DOM Go to Sun Go to CNN Go to NBC document.getElementById(‘list’).getElementsByTagname(‘li’)[1].firstchild;

26 Creating Form Username: *required Password: *required

27 var regExCheck = new RegExp("^\\d{3}$"); function check() { var usr = document.frmLogin.txtUser; var pas = document.frmLogin.passwd.value; if(usr.value == "") { alert("You must enter username."); usr.focus(); document.getElementById('usrSpan').innerHTML = "xxxx"; return false; } if(pas == "") { alert("You must enter password."); document.frmLogin.passwd.focus(); //alert(document.getElementById('passwdSpan').firstChild.nodeValue); document.getElementById('passwdSpan').firstChild.nodeValue = “xxxx”; return false;} if(regExCheck.test(pas)) alert("str: OK"); else { alert("str: Not OK"); document.frmLogin.passwd.value = ""; document.frmLogin.passwd.focus(); return false;} return true; }