Java Script Introduction. Java Script Introduction.

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

The Web Warrior Guide to Web Design Technologies
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction To JavaScript What JavaScript Is: a general purpose scripting language that allows a static page to interact with users and respond to events.
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Javascript and the Web Whys and Hows of Javascript.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Generations of Programming Languages First generation  Machine Language Second Generation  Assembly Language Third Generation  Procedural language such.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Internet Mark-up Languages CO32036 Part Lecture: Elementary JavaScript.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
JavaScript Syntax, how to use it in a HTML document
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
JavaScript Javascript is a scripting language produced by Netscape for use within HTML Web pages. JavaScript is loosely based on Java and it is built into.
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
JavaScript Tutorial First lecture 19/2/2016. Javascript is a dynamic computer programming language. It is lightweight and most commonly used as a part.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Third lecture Event 27/2/2016 JavaScript Tutorial.
CGS 3066: Web Programming and Design Spring 2017
>> Introduction to JavaScript
JavaScript Tutorial Second lecture 22/2/2016.
Chapter 6 JavaScript: Introduction to Scripting
CHAPTER 4 CLIENT SIDE SCRIPTING PART 1 OF 3
CHAPTER 4 CLIENT SIDE SCRIPTING PART 3 OF 3
JavaScript is a programming language designed for Web pages.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Barb Ericson Georgia Institute of Technology May 2006
Exploring JavaScript Ch 14
My First Web Page document.write("" + Date() + ""); To insert.
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript.
CHAPTER 4 CLIENT SIDE SCRIPTING PART 2 OF 3
Chapter 19 JavaScript.
JavaScript Introduction
JavaScript and Ajax (Expression and Operators)
JavaScript an introduction.
DHTML Javascript Internet Technology.
Your 1st Programming Assignment
WEB PROGRAMMING JavaScript.
DHTML Javascript Internet Technology.
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
Lect2 (MCS/BCS) Javascript.
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
Software Engineering for Internet Applications
PHP an introduction.
Web Programming– UFCFB Lecture 13
CNIT 133 Interactive Web Pags – JavaScript and AJAX
Week 5: Recap and Portfolio Site
Web Programming and Design
Presentation transcript:

Java Script Introduction

Java Script lightweight, interpreted programming language designed for creating network-centric applications integrated with HTML implementations allow client-side script to interact with the user and make dynamic pages. first known as LiveScript, but Netscape changed its name to JavaScript Client-side

JavaScript can be implemented using JavaScript statements that are placed within the <script>... </script> Where to place the script tag Within body tag Within head tag External javascript file normally recommended that you should keep it within the <head> tags. <script ...> JavaScript code </script> script tag takes two important attributes Language Type <script language="javascript" type="text/javascript"> JavaScript code </script>

JavaScript is a case-sensitive language Comment <!-- //--> document.write writes a string into our HTML document <html> <body> <script language="javascript" type="text/javascript"> document.write("Hello World!") </script> </body> </html> JavaScript ignores spaces, tabs, and newlines that appear in JavaScript programs JavaScript is a case-sensitive language

Semicolons are Optional <script language="javascript" type="text/javascript"> var1 = 10 var2 = 20 </script> Semicolons are Optional Simple statements in JavaScript are generally followed by a semicolon character,. however, allows you to omit this semicolon if each of your statements are placed on a separate line <script language="javascript" type="text/javascript"> var1 = 10; var2 = 20; </script>

JavaScript in <head>...</head> section <html> <head> <script type="text/javascript"> function sayHello() { alert("Hello World") } </script> </head> <body> <input type="button" onclick="sayHello()" value="Say Hello" /> </body> </html>

JavaScript in <body>...</body> section <html> <head> </head> <body> <script type="text/javascript"> document.write("Hello World") </script> <p>This is web page body </p> </body> </html>

JavaScript in External File 1.Html <html> <head> <script type="text/javascript" src=“a.js" ></script> </head> <body> <input type="button" onclick="sayHello()" value="Say Hello" /> </body> </html> a.js function sayHello() { alert("Hello World") }

JavaScript Datatypes three primitive data types Numbers, eg. 123, 120.50 etc. Strings of text e.g. "This text string" etc. Boolean e.g. true or false. Non primitive data types Object Array Regular Expression Keyword is var Var can hold any type of values E.g. var a=40; var b=“hi”;

Java Script Variables Must start with letter, digits can be followed Can Start with underscore Case sensitive variable names should not start with a numeral JavaScript variables have only two scopes. Global Variables − A global variable has global scope which means it can be defined anywhere in your JavaScript code. Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function. Local E.g. <script> function a() { var a=40; } Global E.g. <script> var d=10; function a() { var a=40; }

Example <html> <body onload = checkscope()> <script type = "text/javascript"> var myVar = "global"; function checkscope( ) { var myVar = "local"; document.write(myVar); } </script> </body> </html>

JavaScript - Operators Arithmetic Operators Comparison Operators Logical (or Relational) Operators Assignment Operators Conditional (or ternary) Operators

Arithmetic Operators <html> <body> <script type="text/javascript"> var a = 33; var b = 10; var c = "Test"; var linebreak = "<br />"; document.write("a + b = "); result = a + b; document.write(result); document.write(linebreak); </script> Set the variables to different values and then try... </body> </html>

typeof Operator <html> <body> <script type="text/javascript"> var a = 10; var b = "String"; var linebreak = "<br />"; result = (typeof b == "string" ? "B is String" : "B is Numeric"); document.write("Result => "); document.write(result); document.write(linebreak); result = (typeof a == "string" ? "A is String" : "A is Numeric"); document.write(result); document.write(linebreak); </script> </body> </html>

JavaScript - Statement If else <script type="text/javascript"> var age = 20; if( age > 18 ) { document.write("<b>Qualifies for driving</b>"); } </script> For <script type="text/javascript"> var count; document.write("Starting Loop" + "<br />") for(count = 0; count < 10; count++) { document.write("Current Count : " + count ); document.write("<br />"); } document.write("Loop stopped!"); </script>

Switch <script type="text/javascript"> var grade='A'; document.write("Entering switch block<br />"); switch (grade) { case 'A': document.write("Good job<br />"); break; case 'B': document.write("Pretty good<br />"); case 'C': document.write("Passed<br />"); case 'D': document.write("Not so good<br />"); case 'F': document.write("Failed<br />"); default: document.write("Unknown grade<br />") } document.write("Exiting switch block"); </script>

JavaScript - Functions Function Definition function keyword followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces. Syntax : function functionname(parameter-list) { statements } function sayHello() { alert("Hello there"); }

JavaScript - Functions Calling a Function <html> <head> <script type="text/javascript"> function sayHello() { document.write ("Hello there!"); } </script> /head> <body> <p>Click the following button to call the function</p> <form> <input type="button" onclick="sayHello()" value="Say Hello"> </form> <p>Use different text in write method and then try...</p> </body> </html>

JavaScript - Functions <html> <head> <script type="text/javascript"> function sayHello(name, age) { document.write (name + " is " + age + " years old."); } </script> </head> <body> <p>Click the following button to call the function</p> <form> <input type="button" onclick="sayHello('Zara', 7)" value="Say Hello"> </form> <p>Use different parameters inside the function and then try...</p> </body> </html>

return Statement <head> <body> <html> <head> <script type="text/javascript"> function concatenate(first, last) { var full; full = first + last; return full; } function secondFunction() var result; result = concatenate('Zara', 'Ali'); document.write (result ); </script> </head> <body> <p>Click the following button to call the function</p> <form> <input type="button" onclick="secondFunction()" value="Call Function"> </form> <p>Use different parameters inside the function and then try...</p> </body> </html>

JavaScript - Events JavaScript's interaction with HTML is handled through events that occur when the user or the browser manipulates a page Developers can use these events to execute JavaScript coded responses, which cause buttons to close windows, messages to be displayed to users, data to be validated, and virtually any other type of response imaginable. Events are a part of the Document Object Model (DOM) onclick Event Type onsubmit Event type onmouseover and onmouseout

which occurs when a user clicks the left button of his mouse onclick Event Type which occurs when a user clicks the left button of his mouse <html> <head> <script type="text/javascript"> <!-- function sayHello() { alert("Hello World") } </script> </head> <body> <p>Click the following button and see result</p> <form> <input type="button" onclick="sayHello()" value="Say Hello" /> </form> </body> </html>

onmouseover and onmouseout <html> <head> <script type="text/javascript"> function over() { document.write ("Mouse Over"); } function out() { document.write ("Mouse Out"); </script> </head> <body> <p>Bring your mouse inside the division to see the result:</p> <div onmouseover="over()" onmouseout="out()"> <h2> This is inside the division </h2> </div> </body> </html>

6 + 4 = 210 9 + 2 = 711 8 + 5 = 313 5 + 2 = 37 7 + 6 = 113 9 + 8 = 117 10 + 6 = 416 15 + 3 = 1218 ?? + ?? = 123