JavaScript Part 1 Introduction to scripting The ‘alert’ function.

Slides:



Advertisements
Similar presentations
Modifying existing content Adding/Removing content on a page using jQuery.
Advertisements

Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Introduction to JavaScript Module 1 Client Side JS Programming M-GO Sponsored By
The Web Warrior Guide to Web Design Technologies
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.
Escaping Characters document.write(). Learning Objectives By the end of this lecture, you should be able to: – Recognize some of the characters that can.
(CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong 1. Overview of Programming and JavaScript - 1
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
Introduction to scripting
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"
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Chapter 4 JavaScript and Dynamic Web pages. Objectives Static Web pages Dynamic Web pages JavaScript Variables Assignments. JavaScript Functions –(prompt(“”,””)
1 JavaScript in Context. Server-Side Programming.
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
JavaScript - A Web Script Language Fred Durao
Return values Efficiency in Coding. Learning Objectives By the end of this lecture, you should be able to: – Be able to apply an ‘object literal’ when.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript Programming Unit #1: Introduction. What is Programming?
Introduction to JavaScript CS101 Introduction to Computing.
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.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
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.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
PHP Form Processing * referenced from
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
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.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
Prepared by Sana Maqbool. Objectives After completing this lesson, the you will be able to… Understand about web authoring Name and explain the uses of.
Prepared by Sana Maqbool. Objectives After completing this lesson, the you will be able to… Understand about web authoring Name and explain the uses of.
Getting Started With HTML
Module 1 Introduction to JavaScript
Tonga Institute of Higher Education IT 141: Information Systems
Moving away from alert() Using innerHTML Using an empty div section
Javascript and Dynamic Web Pages: Client Side Processing
More about comments Review Single Line Comments The # sign is for comments. A comment is a line of text that Python won’t try to run as code. Its just.
Unit M Programming Web Pages with
Chapter 6 JavaScript: Introduction to Scripting
BIT116: Scripting Lecture 06
Concatenation Comments
Microsoft® Office FrontPage® 2003 Training
Section 17.1 Section 17.2 Add an audio file using HTML
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Introduction to Scripting
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript Part 2 Organizing JavaScript Code into Functions
JavaScript.
Intro to PHP & Variables
Introduction to JavaScript
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
A second look at JavaScript
Number and String Operations
Tonga Institute of Higher Education IT 141: Information Systems
WEB PROGRAMMING JavaScript.
JavaScript – Part I Mendelsohn.
T. Jumana Abu Shmais – AOU - Riyadh
Introduction to TouchDevelop
Due Next Monday Assignment 1 Start early
Tonga Institute of Higher Education IT 141: Information Systems
Introduction In today’s lesson we will look at: why Python?
Introduction to JavaScript
JavaScript: Introduction to Scripting
Introduction to JavaScript
Web Programming and Design
Intro to Programming (in JavaScript)
JavaScript Part 2 Organizing JavaScript Code into Functions
Introduction to scripting
Presentation transcript:

JavaScript Part 1 Introduction to scripting The ‘alert’ function

Learning Objectives By the end of this lecture, you should be able to: – Name the two scripting languages most widely used on the web today – List the three locations in which you can place your JavaScripts – Describe what is meant by “case sensitive” – Demonstrate familiarity with the various ways the ‘alert’ function can be used including when and when not to use quotes – FROM MEMORY, be able to create a web document that includes some simple line(s) of JavaScript code

About Scripting Languages A scripting language provides a set of instructions for the computer (via the browser) to follow. Do a calculation Change an image Store some information JavaScript is the #1 (by far) used scripting language on the web. Other well known languages include: – PHP (#2 most popular in the world) – Perl (older, but still very much in use)

JavaScript is not Java This is not a super-important point – I only bring it up here to avoid potential confusion. One is a scripting language, the other is a full-fledged programming language. They do share quite a lot of syntax, however. Java is not easily embedded inside web pages. JavaScript is very easy to embed inside a web page.

Where do you put your scripts? In an HTML document, any script code must be placed inside a tag You can place the tag in both the and sections. – However, most scripts are grouped together inside the section. – We will experiment with both locations. A third location: Scripts may be placed in an entirely separate file (e.g. my_favorite_scripts.js ). That file is then referenced from inside your HTML document. Eg: Scripts that you might want to use in several different pages. For example, a rotating ad banner page. I will try to demonstrate this before the end of the course.

Your first JS function: alert() This is the tool we will use early on in this course to output information back to the user. – Later, we will add another function for outputting: document.write() The alert() function can accept all kinds of information inside the parentheses. The alert() function displays information inside a dialog box that has an ‘okay’ button. When the user clicks the button, the box goes away.

Your first JS JS Practice Welcome to my first JS Page! Let me greet you: alert( "Greetings!" ); You have to tell the browser that you are going to be scripting in JS (there are other scripting languages out there). You can output information using the alert() function. – Note the ;  These are required at the end of nearly ALL lines of JS code.

Inside the section JS Practice alert( "Greetings!" ); Welcome to my first JS Page! Let me greet you: In the previous example, we placed our script inside the section. More commonly, however, we will place our JS code inside the section. One key issue to be aware of, is that anything inside the head section will be displayed by the browser before anything inside the section. So can you predict what will happen here?

Case Sensitivity Many programming languages are “case sensitive”. This means that upper case and lower case letters can not be interchanged – they are considered to be completely different letters! Eg: – alert("Hello World");  no problem – Alert("Hello World");  will not display! So when you study a programming language and learn the syntax of new commands, be sure to pay attention to case!

Only script code can be placed in the tag (i.e. no HTML code) First JS My First JavaScript alert("Hello World"); BAD!!!

– alert("Hello");  Will output the string “Hello” – alert("5+5");  will output the string “5+5” – alert( 5+5 );  will output 10 (discussed shortly) – alert( Date() );  will output the date and time – alert( Math.sqrt(25.0) );  will output the squre root of 25 – alert("5+5 equals " + (5+5) + ".");  Uses a technique called ‘concatenation’. We will discuss this later. Quick note: The alert box is a JavaScript window, it is NOT a miniature web browser. For this reason, you can not place HTML code inside an alert statement. Fun & Games with ‘alert’

If you put information inside quotation marks, we call that text a ‘String’. A String gets output literally on the screen: – alert("Hello World");  Will output “Hello World” – alert("5+5");  will output “5+5” Now notice what happens when we remove the quotes: – alert(5+5);  Will output 10 – Because it is no longer a String, the literal text will NOT be output to the screen. Instead, the JS engine will attempt to treat that text as a JS command. In this case, JS recognizes the ‘+’ symbol as an addition character and will respond accordingly. Example: – alert("Date()");  Will output the string “Date()” – alert(Date());  JS will attempt to execute the command Date() Strings

Your Turn! Remember: It takes practice!!! In programming there is a HUGE difference between “understanding” and actually being able to “do it”. – Trust me on this one… ya gotta practice.

Practice, man, practice Remember: It takes practice!!! We will be building on these skills quite a bit over the next few weeks. If you don’t get the ‘basics’ DOWN, life is going to be rough (at least as far as this course goes) for the duration of the course. It’s not easy to catch up with this stuff – stay on top of it now! If you are not able to create a page with some simple alert statements from memory, than you have not practiced enough!