Java Script Overview By Kevin Harville Java Script
Java. Script Overview By Kevin Harville
Java. Script ® Designed by Netscape and Sun for Browsers. ® Based on the syntax of, but NOT Java. ® Originally Live. Script. Microsoft’s version is Jscript. ECMAScript is standard. We will simply refer to it as Java. Script.
Including Java. Script – 3 possible locations ® General Java. Script is included in the head section of our HTML document. ® Java. Script 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.
The HTML: <script language =“Java. Script” </script> -->
The HTML: <script language =“Java. Script” --> // We can freely indicate comments // Two slashes indicate // a Java. Script Comment /* Slash-Asterisk starts a multi-line Comment. Asterisk-Slash ends it. */ </script>
The HTML: <script language =“Java. Script” --> <!– Comment hides it from old browsers // Use a Java. Script comment also // to end your HTML Comment, like this: // -- > </script>
Event Handlers ® Event Handlers are associated with a particular HTML tag: <input type = “button” on. Click = “alert(‘Hello’)” … >
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.
Recognizing Functions Calling the function from HTML: on. Click = “return say. Hello(‘Hi Class’); ” And in the script in the head section: Function say. Hello(my. Greeting){ alert(my. Greeting); }
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”);
We can write to the document. write(“Hello”) Maybe we want to write HTML: document. write(“<h 1>Hello</h 1>”); 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”);
Writing to the status bar: window. status = “Hello”;
- Slides: 12