Adding JavaScript (<script tag>)

Slides:



Advertisements
Similar presentations
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Advertisements

JavaScript- Processing HTML Forms. Event Handlers Begins with and ends with.
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 Development Identify elements of a Web Page Start Notepad
CIS101 Introduction to Computing Week 09. Agenda Hand in Resume project Your questions Introduction to JavaScript This week online Next class.
CIS101 Introduction to Computing Week 09 Spring 2004.
Introduction to scripting
Prompt box: Example 3 var num1 = prompt("Enter a number between 1 and 12","1") var promptstring = "What is " + num1 + " times 3?" var num2 = prompt(promptstring)
Javascript and the Web Whys and Hows of Javascript.
PHP : Hypertext Preprocessor
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
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.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Week 9 PHP Cookies and Session Introduction to JavaScript.
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.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Chapter 4 JavaScript and Dynamic Web pages. Objectives Static Web pages Dynamic Web pages JavaScript Variables Assignments. JavaScript Functions –(prompt(“”,””)
Objective Static vs. Dynamic Web pages. Variables. Assignments. JavaScript Hierarchy of Objects JavaScript Functions (prompt(“”,””) Document.write(“”)
Client Side Programming with JavaScript Why use client side programming? Web sides built on CGI programs can rapidly become overly complicated to maintain,
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
ITBP 119 Algorithms and Problem Solving Section 2.1 Installing software Section 2.2 First Programs Section 2.3 Variables.
The Grammar of JavaScript.  Each line of a script is a statement  An instruction that JavaScript can evaluate (make sense of)  Ends with a semicolon;
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
JavaScript Adding active content to websites. Goals Understand structure of JavaScript Understand rules of coding Add active content to WebPages Add functions.
LOGO Introduction to Client-Side Scripting and JavaScript CHAPTER 9 Eastern Mediterranean University School of Computing and Technology Department of Information.
1 JavaScript
JavaScript Programming Unit #1: Introduction. What is Programming?
JavaScript Syntax, how to use it in a HTML document
1 A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 4 JavaScript and.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another 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.
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.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
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 Challenges Answers for challenges
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Java Script About Java Script Document Object Model Incorporating JavaScript Adding JavaScript to HTML Embedding a Javascript External Scripts Javascript.
Pertemuan 5 IT133 Pengembangan Web JavaScript. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting.
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.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
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.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
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.
Adding JavaScript ( ) JavaScript Guidelines document.write(" Hello World! ") Link Note: Try this without the tag.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
>> Introduction to JavaScript
Introduction to Client-Side Scripting and JavaScript
Chapter 6 JavaScript: Introduction to Scripting
Chapter 13 - JavaScript/JScript: Introduction to Scripting
My First Web Page document.write("" + Date() + ""); To insert.
Retrieving information from forms
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
PHP Introduction.
JavaScript.
We are starting to program with JavaScript
Lesson 2: Input and Variables
T. Jumana Abu Shmais – AOU - Riyadh
CS105 Introduction to Computer Concepts
Tutorial 10: Programming with javascript
Web Programming– UFCFB Lecture 13
CS105 Introduction to Computer Concepts JavaScript
Retrieving information from forms
Presentation transcript:

Adding JavaScript (<script tag>) <!DOCTYPE html> <html> <head> <title>JavaScript Guidelines</title> <meta charset= "utf-8" /> </head> <body>   <script> document.write("<p>Hello World!</p>") </script> </body> </html> Link Note: Try this without the <script> tag

Example Explained To insert a JavaScript into an HTML page, use the <script> tag. The type attribute defines the scripting language. So, the <script> and </script> tells the browser where the JavaScript starts and ends document.write: standard JavaScript command for writing to a page. The document is the web page “write” is a function available to the document for writing on the web page.. By putting the document.write command between the <script> and </script> tags, the browser recognizes it as a JavaScript command <html> <body> <script > ... </script> </body> </html>

JavaScript is Case Sensitive JavaScript is case sensitive - therefore watch your capitalization closely when you write JavaScript statements, create or call variables, objects and functions. document.write() IS NOT the same thing as Document.write() IS NOT the same thing as document.Write() IS NOT the same thing as Document.Write() Which will actually work?

JavaScript Code JavaScript code (or just JavaScript) is a sequence of JavaScript statements. Each statement is executed by the browser in order Example <script type="text/javascript"> document.write("<h1>This is a header</h1>") document.write("<p>This is a paragraph</p>") document.write("<p>This is another paragraph</p>") </script>

JavaScript Code <!DOCTYPE html> <html> <head> Adding variables example <!DOCTYPE html> <html> <head> <title>JavaScript Guidelines</title> <meta charset= "utf-8" /> </head> <body> <script> var amount = 3 document.write("<h1>Making Decisions</h1>") document.write("<p>There are “ + amount + “choices.</p>") </script> </body> </html>

JavaScript Variables Variables are "containers" for storing information. var x=5, var y=6, var z=x+y These letters are called variables variables can be used to hold values (x=5) A variable can have a short name, like x, or a more descriptive name, like amount. var firstname = “Sam” var lastname = “Smith”

Example <!DOCTYPE html> <html> <head> <meta charset= "utf-8" /> </head> <body> <script> document.write("<p>") var firstname="Fred"; document.write(firstname + "<br />") var lastname = "Flintstone" document.write(lastname) document.write("</p>") var xnum = 3 var ynum = 7 document.write("<p> Total is " + (xnum + ynum) + ".</p>") </script> </body> </html> link

Rules for variable names: Valid names? 4TheDogs my name my-name last_name value2B lastval! sh#!@t Variable names are CASE SENSITIVE (y and Y are two different variables) Variable names MUST NOT contain spaces Variable names must begin with a letter Variable names can only contain letters or numbers or _ No special characters!! Variable names can be anything except words that already belong to javaScript (e.g., document, var, write, etc.)

CreatingVariables The variables now exist, but are empty var x var carname The variables now exist, but are empty they have no values yet. You can give values to the variables when you create them: var x=5 var carname="Volvo" x will hold the value 5, and carname will hold the value Volvo. Note: When you assign a text value to a variable, use quotes around the value. You can always change the value inside a variable: x = 7 carname = “Mazda” Before, x held 5, now it holds 7. carname held “Volvo”, now the value has been changed to “Mazda” You can change the values again if you like.

Another example <!DOCTYPE html> <html> <head> <meta charset= "utf-8" /> </head> <body> <script> document.write(“<p>”); var firstname="Fred"; document.write(firstname + “<br >”);   firstname="Wilma"; document.write(“</p>”); </script> </body> </html> link

Prompt Box What if we want to get input from the user? Use a prompt box Example: <body> <script> var x = prompt(“What state do you live in?",“Delaware") document.write(“<p>You currently live in " + x + “</p>”) </script> </body> link

Prompt Box - deconstructed var x = prompt(“What state do you live in?",“Delaware") Start on right side of = Prompt creates a popup box in which the user can enter text. Within the first set of quotes is what shows up as the prompt’s text “What state do you live in?” In the second set of quotes is the default answer “Delaware” You don’t have to include a default answer Left side of =: a variable (an empty box) named x When the user types something into the prompt box, whatever they typed in is stored in the variable x

Prompt box: Example 2 <!DOCTYPE html> <html> <head> <meta charset= "utf-8" /> </head> <body> <script> var num1 = prompt("Enter a number between 1 and 6","1") document.write("<h"+num1+"> A lovely header of some sort </h"+num1+">") </script> </body> </html> link

Prompt box: Example 3 <!DOCTYPE html> <html> <head> <meta charset= "utf-8" /> </head> <body> <script> var num1 = prompt("Enter a number between 1 and 12","1") var promptstring = "What is " + num1 + " times 3?" var num2 = prompt(promptstring) document.write("<p> You think " + num1 + " times 3 is " + num2 + "</p>") </script> </body> </html> link

Operators (What we can do with numbers) y = 5 Description Example Result + Addition x=y+2 x=7 - Subtraction x=y-2 x=3 * Multiplication x=y*2 x=10 / Division x=y/2 x=2.5 % Modulus (division remainder) x=y%2 x=1

Prompt box: Example 3 <!DOCTYPE html> <html> <head> <meta charset= "utf-8" /> </head> <body> <script> var num1 = parseInt(prompt("Enter a number","1")) var num2 = parseInt(prompt("Enter a second number","1")) document.write("<h2> Fun with numbers </h2>") document.write("<p>") var z = num1 + num2 document.write(num1 + " + " + num2 + " = " + z) document.write("<br >") z = num1 - num2 document.write(num1 + " - " + num2 + " = " + z) z = num1 * num2 document.write(num1 + " * " + num2 + " = " + z) z = num1 / num2 document.write(num1 + " / " + num2 + " = " + z) z = num1 %num2 document.write(num1 + " % " + num2 + " = " + z) document.write("</p >") </script> </body> </html> link

Try: Write a web page with a javascript to write, “Welcome to my very special page” with a line break between my and very. Write a web page that uses the prompt to get the user to input their first name and then their year of birth. Calculate how old they are and write it to the web page (assume you can calculate their age by 2013 – theirage)