JavaScript Defined General Syntax Body vs. Head Variables Math & Logic

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

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.
Computer Science 103 Chapter 4 Advanced JavaScript.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
Introduction To JavaScript What JavaScript Is: a general purpose scripting language that allows a static page to interact with users and respond to events.
آموزش طراحی وب سایت جلسه دهم – جاوا اسکریپت 1 تدریس طراحی وب برای اطلاعات بیشتر تماس بگیرید تاو شماره تماس: پست الکترونیک :
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
Introduction to JavaScript. JavaScript Facts A scripting language - not compiled but interpreted line by line at run-time. Platform independent. It is.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
Internet Mark-up Languages CO32036 Part Lecture: Elementary JavaScript.
JavaScript Informatics for economists I. Introduction Programming language used in web pages. Simple and easy to use – written in HTML document. Client.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
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?
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
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, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
1 JavaScript
44238: Dynamic Web-site Development Client Side Programming Ian Perry Room:C48 Extension:7287
1 JavaScript 2 JavaScript. 2 Rollovers Most web page developers first use JavaScript for rollovers A rollover is a change in the appearance of an element.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES.
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.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
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".
In God we trust Learning Java Script. Java Script JavaScript is the scripting language of the Web! JavaScript is used in millions of Web pages to improve.
JavaScript Lectures Level 7. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting.
Web Development JavaScript. Introduction to JavaScript.
Chapter 4 Java Script - Part1. 2 Outlines Introduction to Java Script Variables, Operators and Functions Conditional statements JavaScript Objects Forms.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
Java Script Introduction. Java Script Introduction.
Introduction to Client-Side Scripting and JavaScript
HTML & teh internets.
JavaScript is a programming language designed for Web pages.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
JavaScript (JS) Basics
Barb Ericson Georgia Institute of Technology May 2006
Web Development & Design Foundations with HTML5 7th Edition
My First Web Page document.write("" + Date() + ""); To insert.
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript.
14 A Brief Look at JavaScript and jQuery.
JavaScript Events.
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
My First Web Page document.write("" + Date() + ""); To insert.
Web Design and Development
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
Web Programming– UFCFB Lecture 13
محمد احمدی نیا JavaScript محمد احمدی نیا
JavaScript and Ajax (JavaScript Events)
CS105 Introduction to Computer Concepts JavaScript
Presentation transcript:

JavaScript Defined General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops  Animation Getting Help

What is JavaScript? JavaScript is NOT Java JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language JavaScript is usually embedded directly into HTML pages JavaScript is an interpreted language (means that scripts execute without preliminary compilation) JavaScript is free and opensource

What can a JavaScript do? JavaScript gives HTML designers a programming tool (very simple syntax) JavaScript can put dynamic text into an HTML page JavaScript can react to events JavaScript can read and write HTML elements JavaScript can be used to validate data (validate form data) JavaScript can be used to detect the visitor's browser JavaScript can be used to create cookies

First JavaScript <html> <head> </head> <body>     <script type="text/javascript">         <!--             document.write("<h1>Hello World!</h1>");         //-->     /script> </body> </html> <!-- Note use of document object model --> <!-- See First_JavaScript.html -->

Body vs. Head <html>     <head>         <script type="text/javascript">             function message()             {                 alert("This alert box called by onload event");             }         </script>     </head>     <body onload="message()">         <script type="text/javascript">             document.write("Message written by JavaScript");         </script>     </body> </html> <!-- See Head_vs_Body.html -->

General Syntax JavaScript statements 'should' end in a semicolon. Large blocks of javascript 'should' be put in { } Comments can be // or <* <script type="text/javascript"> {     document.write("<h1>This is a heading</h1>");     document.write("<p>This is a paragraph.</p>");     document.write("<p>This is another paragraph.</p>");     // Single line comment     /*         Multi-line         comment     */ } </script>

Declaring (Creating) Variables You 'should' declare JavaScript variables with the var statement: var x; var carname; You can also assign values to the variables when you declare them: var x=5; var carname="Volvo"; // Text requires quotes If you assign values to variables that have not yet been declared, the variables will automatically be declared. x=5; carname="Volvo";

Math && Logic Javascript supports the following operators Mathematical: +, -, *, /, %, ++, -- (Note: x=++ Logical: &&, ||, !, <, >, etc... var x=10; var y=2; var z=x/y; Strings can be concatenated with the '+' sign. var txt1="What a very"; var txt2="nice day"; var txt3=txt1+" "+txt2; Note: If you add a number and a string, the result will be a string!

Selection (the 'if' statement) <script type="text/javascript">     //If the time < 10, "Good morning" greeting.     //Otherwise you will get a "Good day" greeting.     var d = new Date();     var time = d.getHours();     if (time < 10){         document.write("Good morning!");     } else {         document.write("Good day!");     } </script>

Popup boxes Three general kinds: alert("sometext"); confirm("sometext");     var r=confirm("Press a button");     if (r==true)       {       document.write("You pressed OK!");       }     else       {       document.write("You pressed Cancel!");       }     } prompt("sometext","defaultvalue"); <!-- See Basic_JavaScript_Stuff.html -->

Functions (Procedures) <html>     <head>         <script type="text/javascript">             function displaymessage()             {                 alert("Hello World!");             }         </script> </head>     <body>         <form>             <input type="button" value="Click me!"                                onclick="displaymessage()" />         </form>     </body> </html>

Loops <html>     <body>         <script type="text/javascript">             var i=0;             for (i=0;i<=5;i++)             {                 document.write("The number is " + i);                 document.write("<br />");             }             while (i<=10)               {                   document.write("The number is " + i);                   document.write("<br />");                   i++;               }         </script>     </body> </html>

Events Every element on a web page has events .     Example: onClick event of a button We define the events in the HTML tags. 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 field in an HTML form     * Submitting an HTML form     * A keystroke Note: Events are normally used in combination with functions, and the function will not be executed before the event occurs!

More Event Types onLoad and onUnload (for pages) onFocus, onBlur and onChange (form fields) onSubmit (forms, all form fields) onMouseOver and onMouseOut (buttons, text, images)   Example: <a href="http://www.w3schools.com" onmouseover="alert('An onMouseOver event');">     <img src="w3s.gif" alt="W3Schools" /> </a>

Animations It is possible to do simple (and complex) animations (and even games) in JavaScript. You can create vector images in JavaScript (you will need to download a special library). You can load and swap bitmap (or jpeg, gif, etc.) images natively. Timing the image swaps can be done using the built in setTimeout method:      t=setTimeout("javascript statement",milliseconds); Examples:     SimpleAnimation1.html     SimpleAnimation2.html     SimpleAnimation3.html

Getting Help W3C JavaScript Tutorial: http://www.w3schools.com/js/default.asp JavaScript Animations: http://www.schillmania.com/content/projects/javascript-animation-1/ JavaScript Games: http://www.devx.com/webdev/10MinuteSolution/27134