4. Javascript Pemrograman Web I Program Studi Teknik Informatika

Slides:



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

Introducing JavaScript
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Javascript Introduction Norman White Material is from w3schools.com Go there to run examples interactively.
The Web Warrior Guide to Web Design Technologies
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
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.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Javascript and the Web Whys and Hows of Javascript.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
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.
DOM and JavaScript Aryo Pinandito.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
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.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
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.
LOGO Introduction to Client-Side Scripting and JavaScript CHAPTER 9 Eastern Mediterranean University School of Computing and Technology Department of Information.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
1 JavaScript
JavaScript Syntax, how to use it in a HTML document
Introduction to JavaScript CS101 Introduction to Computing.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
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. JavaScript is the programming language of HTML and the Web. Easy to learn One of the 3 languages of all developers MUST learn: 1. HTML to.
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.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
1 JavaScript in Context. Server-Side Programming.
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".
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
This is our seminar JavaScript And DOM This is our seminar JavaScript And DOM.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
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. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
Module 1 Introduction to JavaScript
Introduction to Client-Side Scripting and JavaScript
Unit M Programming Web Pages with
Chapter 6 JavaScript: Introduction to Scripting
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Intro to JavaScript CS 1150 Spring 2017.
My First Web Page document.write("" + Date() + ""); To insert.
PHP Introduction.
JavaScript.
JavaScript Introduction
JavaScript an introduction.
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
CS105 Introduction to Computer Concepts
Training & Development
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
Web Programming– UFCFB Lecture 13
Web Programming and Design
CS105 Introduction to Computer Concepts JavaScript
Introduction to Web programming
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

4. Javascript Pemrograman Web I Program Studi Teknik Informatika Universitas Ubudiyah Indonesia

Table of Contents Introduction Java vs JavaScript The <script> Tag JavaScript Function in <head> JavaScript Function in <body> Using an External JavaScript       JavaScript JavaScript JavaScript JavaScript JavaScript Statements Code Variables Data Types Arithmetic      Calling a Function with Arguments Functions With a Return Value JavaScript Data Types JavaScript Operators    

the standard language used in web pages.  JavaScript is the most popular scripting language in the world. It is the standard language used in web pages.  Also widely used by desktop apps, mobile phone apps, and internet servers.  JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create cookies, and much more.

JavaScript is a scripting language (a scripting language is a  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)

Java vs JavaScript Java - Programming Language (PL)  Interactive Web Graphics  Creating web browser applications  Writing stand-alone applications  Developed by Sun Microsystems, a powerful and much more  complex programming language - in the same C++. category as C and JavaScript - Scripting Language   Runs within the context of the Web browser  Customizing pages based on browser version  Visual Feedback to user actions  Validating data entered on HTML Forms

What can JavaScript do?  JavaScript can manipulate HTML JavaScript can read and change the content of HTML elements.  JavaScript can manipulate CSS JavaScript can read and change the style of HTML elements.  JavaScript can validate data JavaScript can be used to validate data, like validating forms input.  JavaScript can react to events JavaScript can be set to execute when something happens, like when a user clicks on an HTML element.

The <script> Tag  A JavaScript is surrounded by a <script> and </script> tag.  The lines between the <script> and </script> contain the JavaScript:.  Example: <script> alert("My First JavaScript"); </script>

Manipulating HTML Elements  To access an HTML element from JavaScript, you can use the document.getElementById(id) method.  Use the "id" attribute to identify the HTML element:

Writing to The Document Output  Use document.write() only to write directly into the document output.

loading, the entire HTML page will be overwritten:  If you execute document.write after the document has finished loading, the entire HTML page will be overwritten:

A JavaScript Function in <head>

A JavaScript Function in <body>

Using an External JavaScript  Scripts can also be placed in external files. External files often contain code to be used by several different web pages.  External JavaScript files have the file extension .js.  To use an external script, point to the .js file in the "src" attribute of the <script> tag:

JavaScript Statements  JavaScript statements are "commands" to the browser. The purpose of the statements is to tell the browser what to do.  Example: document.getElementById("demo").innerHTML="Hello Dolly";  Semicolon separates JavaScript statements.  Normally you add a semicolon at the end of each executable statement.

JavaScript Code statements.  JavaScript code (or just JavaScript) is a sequence of JavaScript statements.  Each statement is executed by the browser in the sequence they are written.

JavaScript Code Blocks  JavaScript statements can be grouped together in blocks start with a left curly bracket, and end with a right curly bracket.  The purpose of a block is to make the sequence of statements execute together as JavaScript functions.

JavaScript is Case Sensitive  Watch your capitalization closely when you write JavaScript statements:  A function getElementById is not the same as getElementbyID.  A variable named myVariable is not the same as MyVariable.

JavaScript Comments  Comments will not be executed by JavaScript.  Comments can be added to explain the JavaScript, or to make the code more readable.  Single line comments start with //.  Multi line comments start with /* and end with */.

JavaScript Variables  Variables are "containers" for storing information:

names, like age, sum, or, totalvolume.  Variable can have a short names, like x and y, or more descriptive names, like age, sum, or, totalvolume.  Rules for JavaScript variable names:  Variable names are case sensitive (y and Y are two different variables)  Variable names must begin with a letter, the $ character, or underscore character the  Example declare JavaScript variables with the var keyword:  var carname;  carname="Volvo";  var carname="Volvo";

JavaScript Data Types of two types: text and numbers.  There are many types of JavaScript variables, but for now, just think of two types: text and numbers.  When you assign a text value to a variable, put double or single quotes around the value.  When you assign a numeric value to a variable, do not put quotes around the value. If you put quotes around a numeric value, it will be treated as text.

One Statement, Many Variables  You can declare many variables in one statement. Just start the statement with var and separate the variables by comma: var name="Doe", age=30, job="carpenter";  Your declaration can also span multiple lines: var name="Doe", age=30, job="carpenter";

JavaScript Arithmetic  As with algebra, you can do arithmetic with JavaScript variables, using operators like = and +:

JavaScript Functions A function is a block of code that executes only when you tell it to execute.   It can be when an event occurs, like when a user clicks a button, or from a call within your script, or from a call within another function.  Functions can be placed both in the <head> and in the <body> section of a document, just make sure that the function exists, when the call is made.  Syntax: function functionname() { some code }

Calling a Function with Arguments  When you call a function, you can pass along some values to it, these values are called arguments or parameters.  These arguments can be used inside the function.  You can send as many arguments as you like, separated by commas (,)  Syntax: myFunction(argument1,argument2)  Declare the argument, as variables, when you declare the function: function myFunction(var1,var2) { some code }

Functions With a Return Value Sometimes you want your function to return a value back to where the call was made. This is possible by using the return statement.   When using the return statement, the function will stop executing,  and return the specified value. Syntax: function myFunction() { var x=5; return x; } 

var myVar=myFunction();  The function-call will be replaced with the returnvalue: var myVar=myFunction();  You can also use the returnvalue without storing it as a variable: document.getElementById("demo").innerHTML=myFunction();

Global JavaScript Variables  Local JavaScript Variables  A variable declared (using var) within a JavaScript function becomes LOCAL and can only be accessed from within that function. (the variable has local scope).  You can have local variables with the same name in different functions, because local variables are only recognized by the function in which they are declared.  Local variables are deleted as soon as the function is completed. Global JavaScript Variables  Variables declared outside a function, become GLOBAL, and all scripts and functions on the web page can access it.

Sekian