Topic: An Introduction to JavaScript - from Beginning JavaScript by Wilton (WROX)

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

Java Script Session1 INTRODUCTION.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
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
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
1 Javascrbipt Intro Javascript (or js) is a programming language. Interpreted, not compiled. Not the same as java, but, similar. Use tags to use. Object-oriented.
JavaScript- Introduction. What it is and what it does? What it is? It is NOT Java It is NOT Server-side programming Users can see code It is a client-side.
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.
Information Technology Center Hany Abdelwahab Computer Specialist.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to JavaScript for Python Programmers
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Introduction to scripting
JAVASCRIPT HOW TO PROGRAM -2 DR. JOHN P. ABRAHAM UTPA.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
JavaScript Part 1.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
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.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
JavaScript - A Web Script Language Fred Durao
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
1 JavaScript
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.
1 A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 4 JavaScript and.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
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.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing a Line of Text in a Web Page 7.3 Another JavaScript.
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
Beginning JavaScript 4 th Edition. Chapter 1 Introduction to JavaScript and the Web.
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.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
1 JavaScript and Dynamic Web Pages Lecture 7. 2 Static vs. Dynamic Pages  A Web page uses HTML tags to identify page content and formatting information.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
JavaScript: A short introduction Joseph Lee Created by Joseph Lee.
CGS 3066: Web Programming and Design Spring 2017
Chapter 6 JavaScript: Introduction to Scripting
“Under the hood”: Angry Birds Maze
Javascript Short Introduction By Thanawat Varintree,
Chapter 7 - JavaScript: Introduction to Scripting
JavaScript: Introduction to Scripting
WEB PROGRAMMING JavaScript.
T. Jumana Abu Shmais – AOU - Riyadh
Tutorial 10: Programming with javascript
Introducing JavaScript
JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Web Programming– UFCFB Lecture 13
Introduction to JavaScript
Web Programming and Design
Chapter 7 - JavaScript: Introduction to Scripting
Presentation transcript:

Topic: An Introduction to JavaScript - from Beginning JavaScript by Wilton (WROX)

What is JavaScript It is not java Interpreted Converted to machine code everytime code is run Java is compiled and Interpteted

History of JavaScript LiveScript Java was trendy – changed the name JScript – the competition Perl and VBScript

Why Use JavaScript User Interaction Getting Information Validating Information Forms Menus Etc.

Getting Started Text Editor or HTML Editor Uses tags for start and end of contents Language Attribute in SCRIPT tag – Opening statement First Code…

Your JavaScript Tutorial document.bgColor = "RED"; Hello There

Java Notes Alert boxes alert(“hello”) or (‘hello’) Start and and with same “” or ‘ ’ ; follow all statements Comment lines // or /* same as in C or Java

Your JavaScript Tutorial // put up an alert box, to show how they work alert("Soon, I will rebuild my browser!"); alert("..and then the world"); document.bgColor = "RED"; Hello There

Static vs Dynamic HTML is static JavaScript is dynamic The word static in the java language means that all objects of a class share the same piece of data can be a behavior or an attribute.

Data Types Weakly types language No explicit declarations of type Works it out for itself Integers and floats var varOne; varOne = “hello”; varOne = 22.33; Assignment varTwo = varOne;

Your JavaScript Tutorial var varOne; varOne = "Hey look at me"; alert(varOne); varOne = 55; alert(varOne); Hello There

Using Data varOne = ; varOne++; varFour = 7/3; varSix = “House”; varSeven = “Red”; varEight = varSix/varSeven

Your JavaScript Tutorial var varOne; varOne = "Hey look at me"; alert(varOne); varOne = 55; alert(varOne); Hello There

Prompting Receiving info from the user Placing results in an alert or a document Adding numbers - parseInt

var varOne = prompt("Enter your name"); alert("Your name is " + varOne+".");

var varOne = prompt("Enter your name"); document.write("Your name is "+varOne+" ");

var varOne = prompt("Enter first number"); var varTwo = prompt("Enter second number"); document.write("The answer is "+varOne+varTwo+" "); alert("Is that correct?"); document.write("The real answer is "+((parseInt(varOne))+(parseInt(varTwo)))+"<BR");

Arrays One dimensional Arrays or multi- dimensional arrays are allowed var myArray1 = new Array() ; or var myArray2 = new Array(5); or Var myArray3= new Array(“the”,”house”); Value of myArray3[0] is ?

var varOne = new Array(); //Total is being incremented each time, so need to initialize it here var Total=0; var counter; for (counter = 0; counter<4; counter++) { varOne[counter] = prompt("Enter number"); //reading from keyboard, need to convert each number from string to int Total+=parseInt(varOne[counter]); } //writes out answer document.write("The answer is "+Total+" "); if (Total>20) document.write("The result is greater than 20 "); else document.write("The result is less than 20 "); document.write("The numbers were "); for (counter in varOne) document.write(""+varOne[counter]+" ");

Why use arrays? Storing just one value in memory at a time does not fulfill your needs. If you wanted to store twenty names you could create twenty unique variables – not efficient –A lot of typing Array – a list of data items that all have the same type and the same name. Easy to fill with a while or for loop

MultiScripted Array Two-dimensional arrays Create an array And then create an array of each item in the array var q = new Array(5); q[0] = new Array(5); Creates a 5x5 array (five rows and five columns)

var questions = new Array(); var answers = new Array(); //Total is being incremented each time, so need to initialize it here var index, counter=0, addMore="yes"; while (addMore == "yes") { questions[counter] = new Array(); questions[0][0] = prompt("Enter First Question"); for (var x = 1; x<5; x++) questions[counter][x] = prompt("Answer choice "+x+" is:"); addMore = prompt("Any more questions?"); counter++ } document.write("The questions were "); for (index=0; index<counter; index++) { document.write(questions[index][0]+" "); for (var x = 1; x< 5; x++) document.write(x+". "+questions[index][x]+" "); answers[index] = prompt("Answer to question "+index+" is"); }

Forms In html page, not JavaScript Textareas, buttons etc. Can use to input or output data

Buttons Adding interactivity to the web page Buttons are part of the html code created in a form. When button clicked can specify some function to activate. –function doThis() –All code in a function is encased in {} Haven’t used functions in previous code today – JavaScript happened automatically when code was run.

Functions Just like methods in Java In this example when button is pressed calls function Function terminates when completed Another button press causes process to start again. Can have global and local variables

var counter = 0; var questions = new Array(); var answers = new Array(); function myButton_doThis() { var index, addMore; addMore="yes"; while (addMore == "yes") { questions[counter] = new Array(); questions[0][0] = prompt("Enter Question +(parseInt(counter)+parseInt(1))); for (var x = 1; x<5; x++) questions[counter][x] = prompt("Answer choice "+x+" is:"); addMore = prompt("Any more questions?"); counter++ } var question; question="The questions were \n"; for (index=0; index<counter; index++) { question+= index+". "+questions[index][0]+"\n"; for (var x = 1; x< 5; x++) question += " "+ x+". "+questions[index][x]+"\n"; window.document.myForm.textAreaOne.value =question; answers[index] = prompt("Answer to question "+index+" is"); }

function myButton_onclick() { window.location.reload(); }

Images Changing images based on user selection var myImages = new Array("station.gif", "stopsign.gif"); var imgIndex = prompt("enter a zero or a one"); document.images["img1"].src = myImages[imgIndex];

Quick Review JavaScript is not Java But it uses many of the basic concepts of many languages: such as assignment, arrays, functions etc. It is interpreted. Works with HTML

Lab Assignment Create an html document which includes JavaScript to ask the user a series of questions and then output the responses to the web page. Use color, prompts, arrays and alert boxes.