Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript Overview By Kevin Harville.

Similar presentations


Presentation on theme: "JavaScript Overview By Kevin Harville."— Presentation transcript:

1 JavaScript Overview By Kevin Harville

2 JavaScript Designed by Netscape and Sun for Browsers.
Based on the syntax of, but NOT Java. Originally LiveScript. Microsoft’s version is Jscript. ECMAScript is standard. We will simply refer to it as JavaScript.

3 Including JavaScript – 3 possible locations
General JavaScript is included in the head section of our HTML document. JavaScript displayed at a particular point in a page is inserted at that point. Event Handlers are attached to HTML elements. They are run when an action associated with that tag takes place.

4 The HTML: <script language =“JavaScript” --> </script>

5 The HTML: </script> <script language =“JavaScript” -->
// We can freely indicate comments // Two slashes indicate // a JavaScript Comment /* Slash-Asterisk starts a multi-line Comment. Asterisk-Slash ends it. */ </script> </script>

6 The HTML: <script language =“JavaScript” -->
<!– Comment hides it from old browsers // Use a JavaScript comment also // to end your HTML Comment, like this: // -- > </script>

7 Event Handlers Event Handlers are associated with a particular HTML tag: <input type = “button” onClick = “alert(‘Hello’)” … >

8 Event Handlers and Functions
Usually an event handler will refer to a function. A function is a section of code that performs a particular task and can give you the answer of a computation. Function code is usually in the head section.

9 Recognizing Functions
Calling the function from HTML: onClick = “return sayHello(‘Hi Class’);” And in the script in the head section: Function sayHello(myGreeting){ alert(myGreeting); }

10 Generating Text Output:
We can quickly generate 3 types of prompt windows: Alert(“Hello”); Answer = confirm(“Continue?”); Answer = prompt(“Enter your name”); The default answer is optional: Answer = prompt(“What is your name?”, “Homer”);

11 We can write to the document
document.write(“Hello”) Maybe we want to write HTML: document.write(“<h1>Hello</h1>”); If we want to make sure that the text file has a line break we can use writeln rather than write. document.writeln(“Go to a new line”);

12 Writing to the status bar:
window.status = “Hello”;


Download ppt "JavaScript Overview By Kevin Harville."

Similar presentations


Ads by Google