Download presentation
Presentation is loading. Please wait.
1
Introduction to Javascript
2
What HTML Can & Can Not Do
Display text Display images Display animated clipart Allow users to input data HTML Can Not Do calculations Display current date Check validity of input data Respond to user actions Be interactive
3
Programming For a Web Page to be able to be interactive
Calculate Display current date Check validity of input data Add dynamic effects You need to include a program A set of detailed instruction to the computer to accomplish some task Using a programming language JavaScript VBScript php perl
4
What Is Javascript? (Now called EcmaScript)
A scripting language used to add greater power and interactivity to Web pages Freely combined with HTML in the Web document Invented by Netscape, now controlled by Ecma International Often called a scripting language, rather than a programming language Distinct from Java, which is a full-fledged programming language invented by Sun Microsystems.
5
Sample Web Page with Javascript
Alert Demo (JS code) Prompt Demo (JS code) Date Demo (JS code)
6
Other Examples of JS Use
Create a new window on the fly. Check validity of form entries. Manipulate document objects.
7
Calling Functions Greet on Click (Code)
Change Background on MouseOver (Code) Alert on Click (Code)
8
<html> <head> <title>JS Demo</title> <script language="Javascript"> function greet() { alert("Hello"); } </script> </head> <body> <h1>Javascript ONCLICK Demo</h1> <form> <input type="button" value="Click Me“ onClick="greet()"> </form> </body> </html> Greet on Click
9
Change Background on MouseOver
<html> <head> <title>JS Demo</title> <script language="Javascript"> function toBlue() { document.bgColor="0000ff| } function toWhite() { document.bgColor="ffffff"; } </script> </head> <body> . . .
10
. . . <body> <h1>Javascript ONMOUSEOVER Demo</h1> <form> <input type="button" onMouseOver="toBlue()“ onMouseOut="toWhite()"> </form> </body> </html
11
Alert on Click <html> <head> <title>JS Demo</title> <script language="Javascript"> function quote(mesg){ alert(mesg); } </script> </head> <body> <h1>Famous Quotes</h1> <form> <input type=“button” value=“Lincoln” onClick="quote('Four scores and seven years ago...')">
12
. . . <input type=“button” value=“Washington” onClick="quote('I cannot tell a lie.')"> <input type=“button” value=“Kennedy” onClick="quote('Let the race (to the moon) begin.')"> </from> </body> </html
13
Where to Embed JS Function (1)
<html> <head><title>JS Demo</title> </head> <body> <h1>Javascript Demo</h1> <script language="Javascript"> <!– Javascript code goes here. //--> </script> </body> </html>
14
Where to Embed JS Function (2)
<html> <head><title>JS Demo</title> <script language="Javascript"> function greet() { alert("Hello"); } </script> </head> <body> <h1>Javascript ONCLICK Demo</h1> <form> <input type="button" value="Click Me" onClick="greet()"> </form> </body> </html> Where to Embed JS Function (2)
15
Javascript Language Basics
16
General Rules JS is case sensitive. Statements end with a semicolon.
Sum = n1 + n2; // These statements are different sum = N1 + N2; Statements end with a semicolon. today = new Date(); Comments // This form is for short comments to end of line /* This form of delimiters can span several lines of comments. */
17
Variables firstName = "Maria"; // String value lastName = "Martinez"; // " myMotto = "Be Prepared"; // " myAge = 21; // integer value priceOfBook = 27.25; // float value priceOfCD = 18.50; // "
18
Operators // concatenation operator fulName = firstName + " " + lastName; // arithmetic operator totalPrice = priceOfBook + priceOfCD; // arithmetic operator ageOfMyBrother = myAge - 2;
19
Pre-defined Functions
// current date and time today = new Date(); // year value (integer) of today year = today.getYear(); // pop up a window displaying alert("Welcome to Honolulu"); // prints string to the current page document.write("Hello."). document.writeln(" Good-bye");
20
User-defined Functions
function greet() { alert("Welcome to Hawaii."); } function greetWithName(name) { alert("Welcome to Hawaii, " + name); } function changeBackColor(someColor) { alert("Here is a new background color."); document.bgColor = someColor; }
21
Events Partial List of Events
Event is an action external to the program that triggers a code to be executed. Partial List of Events Event Works with When Onclick A, INPUT (e.g., button), FORM, TABLE, & many others an element is clicked
22
Event Works with When onblur A, AREA, BUTTON, INPUT, LABEL, SELECT, TEXTAREA the mouse leaves an element which was in focus onload BODY, FRAMESET a page is loaded into the browser ondblclick Same as ONCLICK an element is double-clicked onmouseover mouse is moved over the element onmouseout mouse is moved out of the element's area
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.