1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.

Slides:



Advertisements
Similar presentations
1 Copyright © 2002 Pearson Education, Inc.. 2 Chapter 2 Getting Started.
Advertisements

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 12 – Security Panel Application Introducing.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
© 2012 National Heart Foundation of Australia. Slide 2.
Introducing JavaScript
Project 6: Working with If Statements Essentials for Design JavaScript Level One Michael Brooks.
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
Types of selection structures
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
PSSA Preparation.
Presentation 7: JavaScript continued Control structures and functions Fundamentals of Web-Centric Development.
CMPT 100 : INTRODUCTION TO COMPUTING TUTORIAL #5 : JAVASCRIPT 2 GUESSING GAME By Wendy Sharpe 1.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
The Web Warrior Guide to Web Design Technologies
HTML Forms JavaScript Introduction / Overview Lab Homework #1 CS 183 4/8/2010.
Tutorial 10 Programming with JavaScript
Web Page Behavior IS 373—Web Standards Todd Will.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
آموزش طراحی وب سایت جلسه دهم – جاوا اسکریپت 1 تدریس طراحی وب برای اطلاعات بیشتر تماس بگیرید تاو شماره تماس: پست الکترونیک :
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
CC1003N Week 6 More CSS and Javascript.. Objectives: ● More CSS Examples ● Javascript – introduction ● Uses of Javascript ● Variables ● Comments ● Control.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
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.
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
Using Client-Side Scripts to Enhance Web Applications 1.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
JavaScript - A Web Script Language Fred Durao
JavaScript Adding active content to websites. Goals Understand structure of JavaScript Understand rules of coding Add active content to WebPages Add functions.
1 JavaScript
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
By Tharith Sriv. To write a web page you use: HHTML (HyperText Markup Language), AASP (Active Server Page), PPHP (HyperText Preprocessor), JJavaScript,
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
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 Server versus Client-Side Programming Server-SideClient-Side.
Making dynamic pages with javascript Lecture 1. Java script java versus javascript Javascript is a scripting language that will allow you to add real.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Pertemuan 5 IT133 Pengembangan Web JavaScript. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
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,
Web Development JavaScript. Introduction to JavaScript.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Chapter 5: Intro to Scripting CIS 275—Web Application Development for Business I.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
JavaScript Tutorial First lecture 19/2/2016. Javascript is a dynamic computer programming language. It is lightweight and most commonly used as a part.
PHP using MySQL Database for Web Development (part II)
CHAPTER 10 JAVA SCRIPT.
Tutorial 10 Programming with JavaScript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript.
PHP.
CS105 Introduction to Computer Concepts
Tutorial 10 Programming with JavaScript
Tutorial 10: Programming with javascript
PHP an introduction.
Web Programming– UFCFB Lecture 13
CS105 Introduction to Computer Concepts JavaScript
Presentation transcript:

1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight programming language A JavaScript consists of lines of executable computer code A JavaScript is usually embedded directly into HTML pages JavaScript is an interpreted language (means that scripts execute without preliminary compilation) Everyone can use JavaScript without purchasing a license

2 What can a JavaScript Do? JavaScript gives HTML designers a programming tool - HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages JavaScript can put dynamic text into an HTML page - A JavaScript statement like this: document.write(" " + name + " ") can write a variable text into an HTML page JavaScript can react to events - A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element JavaScript can read and write HTML elements - A JavaScript can read and change the content of an HTML element

3 What can a JavaScript Do? JavaScript can be used to validate data - A JavaScript can be used to validate form data before it is submitted to a server. This saves the server from extra processing JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect the visitor's browser, and - depending on the browser - load another page specifically designed for that browser JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve information on the visitor's computer

4 How to Put a JavaScript Into an HTML Page document.write("Hello World!")

5...

6 <!– document.write("Hello World!") //-->

7 Where to Put the JavaScript Head section Body section External script

8 Scripts in the head section....

9 Scripts in the body section....

11 Using an External JavaScript Note: The external script cannot contain the tag!

12 Writing output to a page document.write is a standard JavaScript command for writing output to a page. document.write(“Hello, World!”) document is the object write is the method

13 JavaScript Popup Boxes Alert Box Confirm Box Prompt Box

14 Alert box An alert box is often used if you want to make sure information comes through to the user. When an alert box pops up, the user will have to click "OK" to proceed. Syntax: alert("sometext")

15 Confirm Box A confirm box is often used if you want the user to verify or accept something. When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed. If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false. Syntax: confirm("sometext")

16 Prompt Box A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value. If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null. Syntax prompt("sometext","defaultvalue")

17 JavaScript Variables Variables are used to store data. A variable's value can change during the script. You can refer to a variable by name to see its value or to change its value. Rules for variable names: Variable names are case sensitive They must begin with a letter or the underscore character

18 Declaring and Using a Variable It is declared by assigning it a value or using the var command var myVariable; var myVariable=“Hello”; myVariable=“Hello”; Variables should be declared immediately before using the variable

19 Using the Prompt to assign Variables The prompt allows the user to input a response The response can be stored in a variable to be used elsewhere var visitorName; visitorName=prompt(“What is your name?”, “Enter your name here.”);

20 JavaScript Operators Arithmetic Operators Assignment Operators Comparison Operators Logical Operators String Operator Conditional Operator operators.php

21 Basic Math Purchase 2 CDs and 3 dvds var cdPrice=12.00; var dvdPrice=15.00; var Totalcost; Totalcost= 2*cd + 3*vcd

22 JavaScript Conditional Statements Conditional statements in JavaScript are used to perform different actions based on different conditions.

23 If Statement if (condition) { code to be executed if condition is true }

24 If...else Statement if (condition) { code to be executed if condition is true } else { code to be executed if condition is not true }

25 If...else if...else Statement if (condition1) { code to be executed if condition1 is true } else if (condition2) { code to be executed if condition2 is true } else { code to be executed if condition1 and condition2 are not true }

26 JavaScript Switch Statement switch(n) { case 1: execute code block 1 break case 2: execute code block 2 break default: code to be executed if n is different from case 1 and 2 }

27 JavaScript Functions A function is a reusable code-block that will be executed by an event, or when the function is called. Functions can be defined both in the and in the section of a document. However, to assure that the function is read/loaded by the browser before it is called, it could be wise to put it in the section.

28 How to Define a Function function functionname(var1,var2,...,varX) { some code }

29 Function with no parameters function functionname() { some code }

30 The return Statement The return statement is used to specify the value that is returned from the function.

31 function prod(a,b) { x=a*b return x } product=prod(2,3)

32 JavaScript Loops For loop While and Do while Loop For..in

33 For Loop for(var=startvalue;var<=endvalue;var=var+increment) { code to be executed }

34 For Loop var i=0 for (i=0;i<=10;i++) { document.write("The number is " + i) document.write(" ") }

35 While and Do-While while (var<=endvalue) { code to be executed } do { code to be executed } while (var<=endvalue)

36 While loop var i=0; while (i<=10) { document.write("The number is " + i) document.write(" ") i=i+1 }

37 Do -while var i=0 ; do { document.write("The number is " + i) document.write(" ") i=i+1 } while (i<0)

38 JavaScript For...In Statement for (variable in object) { code to be executed }

39 Using for...in to loop through an array: var x var mycars = new Array() mycars[0] = "Saab" mycars[1] = "Volvo“ mycars[2] = "BMW" for (x in mycars) { document.write(mycars[x] + " ") }

40 JavaScript Events Events are actions that can be detected by JavaScript. Examples of events: A mouse click A web page or an image loading Mousing over a hot spot on the web page Selecting an input box in an HTML form Submitting an HTML form A keystroke

41 ตัวอย่าง Event onAbort เกิดเมื่อผู้ใช้ยกเลิกการโหลด เอกสารหรือภาพ onBlur เกิดเมื่ออ็อบเจ็กต์นั้นถูกย้าย focus ออกไป onChange เมื่อผู้ใช้เปลี่ยนแปลงค่าในฟอร์มรับ ข้อมูล onClick เกิดเมื่ออ็อบเจ็กต์นั้นถูก click onError เกิดเมื่อการโหลดเอกสารหรือภาพ เกิด ข้อผิดพลาด onFocus เกิดเมื่ออ็อบเจ็กต์นั้นถูก focus onLoad เกิดเมื่อโหลดเอกสารเสร็จ

42 onMouseover เกิดเมื่ออ็อบเจ็กต์นั้นถูกเลื่อนเมาส์ ไปทับ onMouseout เกิดเมื่ออ็อบเจ็กต์นั้นถูกเลื่อน เมาส์ที่ทับออกไป onSelect เกิดเมื่อผู้ใช้เลือกข้อความใน ช่องรับข้อความ onSubmit เกิดเมื่อผู้ใช้ submit แบบฟอร์ม onUnload เกิดเมื่อผู้ใช้ออกจากเวบเพจ

43 JavaScript Objects Introduction JavaScript is an Object Oriented Programming (OOP) language. An OOP language allows you to define your own objects and make your own variable types.

44 Properties Properties are the values associated with an object. var txt="Hello World!“; document.write(txt.length);

45 Methods Methods are the actions that can be performed on objects. var str="Hello world!" document.write(str.toUpperCase) ()

46 JavaScript String Object The String object is used to manipulate a stored piece of text.

47 Length property length property of the String object to find the length of a string: var txt="Hello world!" document.write(txt.length)

48 toUpperCase() method the toUpperCase() method of the String object to convert a string to uppercase letters: var txt="Hello world!" document.write(txt.toUpperCase())

49 การดำเนินการกับข้อความ CharAt( เลขที่ตำแหน่ง ) IndexOf(pattern) IndexOf(pattern,startIndex) lastIndexOf(pattern) lastIndexOf(pattern,startIndex) Spilt(separator) Substring(startIndex,endIndex) toLowerCase() toUpperCase()

50 JavaScript Date Object The Date object is used to work with dates and times. Defining Dates var myDate=new Date()

51 document.write(Date())

52 Date Object Method getDate() getDay() getMonth() getFullyear() getYear() getHours() getMinutes() getSeconds()

53 JavaScript Math Object The Math object allows you to perform common mathematical tasks.

54 Math Object Methods max(x,y) min(x,y) pow(x,y) round(x) ceil(x) Etc...

55 JavaScript Array Object The Array object is used to store a set of values in a single variable name. Defining Arrays var myArray=new Array()

56 var mycars=new Array() mycars[0]="Saab" mycars[1]="Volvo" mycars[2]="BMW" var mycars=new Array(3) mycars[0]="Saab" mycars[1]="Volvo" mycars[2]="BMW"

57 var mycars=new Array("Saab","Volvo","BMW") ว

58 Accessing Arrays You can refer to a particular element in an array by referring to the name of the array and the index number. The index number starts at 0. document.write(mycars[0])

59 More on Javascripts d_tutorial/ d_tutorial/ shtml shtml shtml shtml or.shtml or.shtml

60 Navigator object navigator.appname navigator.appcodename navigator.appVersion navigator.langauge navigator.mimetype[] navigator.platform navigator.plugin

61 สร้างเครื่องคิดเลขดังรูป ( ใช้รูปที่ angsila.cs.buu.ac.th/~pan/321370/images)