JavaScript Guide

JavaScript Guide contents Introduction What's new in Navigator 3.0 What you should already know How to use this book Document conventions

Introduction

Part 1. Using JavaScript in Navigator 1. Getting started What is JavaScript? Embedding JavaScript in HTML Defining and calling functions Using the write method Scripting event handlers Validating form input 2. Using Navigator objects Navigator object hierarchy document properties: an example JavaScript reflection and HTML layout Key Navigator objects Navigator's object arrays 3. Using windows and frames Opening and closing windows Using frames Referring to windows and frames Navigating among windows and frames 4. LiveConnect Enabling LiveConnect The Java Console About the Netscape packages JavaScript to Java communication Java to JavaScript

avaScript is a compact, object-based scripting language for developing client and server Internet applications. Netscape Navigator interprets JavaScript statements embedded in an HTML page, and LiveWire enables you to create server-based applications similar to Common Gateway Interface (CGI) programs. This book describes the JavaScript language and its use in Navigator. For information on developing server-based JavaScript applications, see the LiveWire Developer's Guide.

What's new in Navigator 3.0
JavaScript for Navigator 3.0 has a rich set of new features. Appendix F, "Features added after version 1," lists the new objects, properties, arrays, methods, functions, event handlers, operators, and other features.

What you should already know
This book assumes you have some basic background, including
q

q

A general understanding of the Internet and the World Wide Web (WWW). Good working knowledge of HyperText Markup Language (HTML).

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/INDEX~1.HTM (1 of 9) [30/08/2003 9:33:57 PM]

JavaScript Guide

communication 5. Advanced topics Using JavaScript URLs Using client-side image maps Using server-side image maps Using the status bar Using cookies Using data tainting for security Determining installed plug-ins

Some programming experience with a language such as C or Visual Basic is useful, but not required.

How to use this book
This book is divided into three parts:
q

Part 2. The JavaScript Language 6. Values, variables, and literals Values Variables Literals 7. Expressions and operators Expressions Operators 8. Object model Objects and properties Functions Creating new objects 9. Built-in objects and functions Built-in objects Built-in functions 10. Overview of JavaScript statements Conditional statement Loop statements Object manipulation statements and operators Comments

q

q

Part 1, "Using JavaScript in Navigator," introduces JavaScript and describes its use in Navigator. It covers the main features of client JavaScript and touches on some advanced topics. Part 2, "The JavaScript languag," describes the syntax and semantics of the JavaScript language itself and is applicable to both client-side and server-side JavaScript. It also describes JavaScript's built-in String, Math, and Date objects, built-in functions, and statement syntax. Part 3, "Reference," is a comprehensive, alphabetical reference for Navigator JavaScript. It includes a chapter on JavaScript statements and one for all objects, properties, and methods in Navigator JavaScript.

If you are new to JavaScript, start with Chapter 1, "Getting started" to start scripting your own pages immediately. Then continue with the chapters in Part 1, to learn more about JavaScript in Navigator. You may find it useful to skim the material in Part 2, particularly Chapter 8, "Object model." Use the reference material in Part 3 as necessary for details on specific topics. If you are already familiar with JavaScript in Navigator, skim the material in Part 1, paying particular attention to the chapters that discuss more advanced topics: Chapter 3, "Using windows and frames" and Chapter 5, "Advanced topics." You can then use the reference material as needed. If you are a LiveWire application developer, use the material in Part 1 to familiarize yourself with the basics of JavaScript. Then read Part 2 for a more in-depth look at the JavaScript language. All the material in Part 2 is applicable to LiveWire JavaScript. You need to read only material on client JavaScript if you want to incorporate only client functionality into your applications.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/INDEX~1.HTM (2 of 9) [30/08/2003 9:33:57 PM]

JavaScript Guide

Part 3. Reference 11. Statements break comment continue for for...in function if...else new return this var while with 12. The Netscape packages netscape.javascript.JSObject netscape.javascript.JSException netscape.plugin.Plugin 13. Navigator JavaScript reference abs acos action alert alinkColor anchor method Anchor object anchors appCodeName Applet applets appName appVersion Area arguments array arguments property Array asin atan atan2

Document conventions
Netscape Navigator runs on many different operating systems; the information here applies to all versions. File and directory paths are given in Windows format (with backslashes separating directory names). For Unix versions, the directory paths are the same, except slashes instead of backslashes separate directories. Figures that show screens were created using Windows NT. Screens on your platform may look different. This book uses Uniform Resource Locators (URLs) of the form http://server.domain/path/file.html In these URLs, server represents the name of the server on which you are running LiveWire, such as "research1" or "www," and domain represents your Internet domain name, such as "netscape.com" or "uiuc.edu." If you have configured your proxy, you might not need to specify your domain name when the client itself is within the domain. In general, italic items in URLs are variables, and items in normal Courier font are literals. This book uses the following typographical conventions:
q

q

q

File and directory names are shown in fixed-pitch font, for example, c:\javascript\samples\world\hello.html. JavaScript method and function names are shown in boldface without any parentheses; for example, write and alert. JavaScript object and property names are shown in italics; for example, document.title and Date object.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/INDEX~1.HTM (3 of 9) [30/08/2003 9:33:57 PM]

JavaScript Guide

back bgColor big blink blur bold Boolean border Button caller ceil charAt Checkbox checked clearTimeout click close (document object) close (window object) closed complete confirm constructor cookie cos current Date defaultChecked defaultSelected defaultStatus defaultValue description document domain E elements array elements property embeds array enabledPlugin encoding escape eval exp fgColor filename FileUpload
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/INDEX~1.HTM (4 of 9) [30/08/2003 9:33:57 PM]

JavaScript Guide

fixed floor focus fontcolor fontsize Form object form property forms forward Frame frames Function getDate getDay getHours getMinutes getMonth getSeconds getTime getTimezoneOffset getYear go hash height Hidden history array history object host hostname href hspace Image images index indexOf isNaN italics javaEnabled join lastIndexOf lastModified length link method Link object linkColor
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/INDEX~1.HTM (5 of 9) [30/08/2003 9:33:57 PM]

JavaScript Guide

links LN2 LN10 location log LOG2E LOG10E lowsrc Math max MAX_VALUE method MimeType mimeTypes min MIN_VALUE name NaN navigator NEGATIVE_INFINITY next Number onAbort onBlur onChange onClick onError onFocus onLoad onMouseOut onMouseOver onReset onSelect onSubmit onUnload open (document object) open (window object) opener Option options parent parse parseFloat parseInt Password
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/INDEX~1.HTM (6 of 9) [30/08/2003 9:33:57 PM]

JavaScript Guide

pathname PI Plugin plugins port POSITIVE_INFINITY pow previous prompt protocol prototype Radio random referrer refresh reload replace reset method Reset object reverse round scroll search select method Select object selected selectedIndex self setDate setHours setMinutes setMonth setSeconds setTime setTimeout setYear sin small sort split sqrt SQRT1_2 SQRT2 src status
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/INDEX~1.HTM (7 of 9) [30/08/2003 9:33:57 PM]

JavaScript Guide

strike String sub submit method Submit object substring suffixes sup taint taintEnabled tan target Text object text property Textarea title toGMTString toLocaleString toLowerCase top toString toUpperCase type unescape untaint URL userAgent UTC value valueOf vlinkColor vspace width window object window property write writeln A. Object summary B. Reserved words C. Color values D. Netscape cookies
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/INDEX~1.HTM (8 of 9) [30/08/2003 9:33:57 PM]

JavaScript Guide

E. LiveAudio and LiveConnect F. Features added after version 1 Index

Copyright © 1995-1996 Netscape Communications Corporation Last modified undefined

Hide Left Frame

Show Index

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/INDEX~1.HTM (9 of 9) [30/08/2003 9:33:57 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/intro.htm

Introduction

avaScript is a compact, object-based scripting language for developing client and server Internet applications. Netscape Navigator interprets JavaScript statements embedded in an HTML page, and LiveWire enables you to create server-based applications similar to Common Gateway Interface (CGI) programs. This book describes the JavaScript language and its use in Navigator. For information on developing server-based JavaScript applications, see the LiveWire Developer's Guide.

What's new in Navigator 3.0
JavaScript for Navigator 3.0 has a rich set of new features. Appendix F, "Features added after version 1," lists the new objects, properties, arrays, methods, functions, event handlers, operators, and other features.

What you should already know
This book assumes you have some basic background, including
q q

A general understanding of the Internet and the World Wide Web (WWW). Good working knowledge of HyperText Markup Language (HTML).

Some programming experience with a language such as C or Visual Basic is useful, but not required.

How to use this book
This book is divided into three parts:
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/intro.htm (1 of 3) [30/08/2003 9:33:57 PM]

and Date objects. to learn more about JavaScript in Navigator." describes the syntax and semantics of the JavaScript language itself and is applicable to both client-side and server-side JavaScript. It includes a chapter on JavaScript statements and one for all objects.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/intro. Math. For Unix versions. Then continue with the chapters in Part 1. It also describes JavaScript's built-in String. "Reference." You can then use the reference material as needed. alphabetical reference for Navigator JavaScript. paying particular attention to the chapters that discuss more advanced topics: Chapter 3. Part 3. the information here applies to all versions. Figures that show screens were created using Windows NT. server represents the name of the server on which you are running LiveWire. If you are a LiveWire application developer." introduces JavaScript and describes its use in Navigator. This book uses Uniform Resource Locators (URLs) of the form http://server. except slashes instead of backslashes separate directories. start with Chapter 1. built-in functions." Use the reference material in Part 3 as necessary for details on specific topics.htm (2 of 3) [30/08/2003 9:33:57 PM] . You need to read only material on client JavaScript if you want to incorporate only client functionality into your applications. "Object model. All the material in Part 2 is applicable to LiveWire JavaScript. File and directory paths are given in Windows format (with backslashes separating directory names). particularly Chapter 8. Document conventions Netscape Navigator runs on many different operating systems. If you are new to JavaScript. "Advanced topics. properties. skim the material in Part 1. It covers the main features of client JavaScript and touches on some advanced topics.htm q q q Part 1. the directory paths are the same. Then read Part 2 for a more in-depth look at the JavaScript language. "Using JavaScript in Navigator. "The JavaScript languag. "Using windows and frames" and Chapter 5. and methods in Navigator JavaScript. Screens on your platform may look different.html In these URLs. You may find it useful to skim the material in Part 2. "Getting started" to start scripting your own pages immediately.domain/path/file. such as file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/intro. Part 2. and statement syntax. use the material in Part 1 to familiarize yourself with the basics of JavaScript. If you are already familiar with JavaScript in Navigator." is a comprehensive.

you might not need to specify your domain name when the client itself is within the domain. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/intro.edu." and domain represents your Internet domain name. for example. and items in normal Courier font are literals. This book uses the following typographical conventions: q q q File and directory names are shown in fixed-pitch font.title and Date object.com" or "uiuc.html. c:\javascript\samples\world\hello. such as "netscape.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/intro. JavaScript object and property names are shown in italics." If you have configured your proxy. italic items in URLs are variables. In general.htm (3 of 3) [30/08/2003 9:33:57 PM] . write and alert. JavaScript method and function names are shown in boldface without any parentheses. for example. document.htm "research1" or "www. for example.

discusses some of the fundamental concepts of JavaScript in Navigator and provides basic examples. you can write a JavaScript function to verify that users enter valid information into a form requesting a telephone number or zip code. form input.htm Getting started his chapter introduces JavaScript. Without any network transmission. and page navigation. the HTML page with embedded JavaScript can check the entered data and alert the user with a dialog box if the input is invalid. There are two types of JavaScript: q q Navigator JavaScript. object-based scripting language for client and server applications. In contrast to Navigator JavaScript. producing the results that the user sees. JavaScript in LiveWire LiveWire is an application development environment that uses JavaScript for creating server-based applications similar to CGI (Common Gateway Interface) programs. using the example code as a starting point. Client-side JavaScript statements embedded in an HTML page can respond to user events such as mouse-clicks. so you can begin writing your own scripts immediately. LiveWire JavaScript applications are compiled into bytecode executable files. This process is illustrated in the following figure. It shows JavaScript code in action. The Navigator then displays the HTML and executes the JavaScript.0 (and later versions) can interpret JavaScript statements embedded in an HTML page. over the network to the client. also called server-side JavaScript JavaScript in Navigator Netscape Navigator 2. These application executables are run in concert with a Netscape server (version 2.0 and later) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. For example. When Navigator requests such a page.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. including HTML and JavaScript statements.htm (1 of 16) [30/08/2003 9:33:59 PM] . What is JavaScript? JavaScript is Netscape's cross-platform. also called client-side JavaScript LiveWire JavaScript. the server sends the full content of the document.

JavaScript and Java JavaScript and Java are similar in some ways but fundamentally different in others. facilitating rapid development and easy maintenance. and multiple applications. the language As described in the previous sections.htm that contains the LiveWire server extension.1 is for Navigator 3. LiveWire JavaScript also provides objects and methods for database access that serve as an interface to Structured Query Language (SQL) database servers. For example. For information. this HTML (which may also include client-side JavaScript statements) is then sent by the server over the network to the Navigator client. JavaScript supports most Java expression syntax and basic control-flow constructs. JavaScript has a file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. JavaScript. LiveWire JavaScript is integrated directly into HTML pages. Boolean. The LiveWire server extension generates HTML dynamically. statement syntax. variables. and literals Underlying object model (although Navigator and LiveWire have different object frameworks) Built-in objects and functions So. if you have LiveWire. you will often be able to write functions that work on either the client or the server. which displays the results. For more information on LiveWire.htm (2 of 16) [30/08/2003 9:33:59 PM] . but they have the following elements in common: q q q q Keywords. In contrast to Java's compile-time system of classes built by declarations. see "Specifying the JavaScript version". In contrast to standard CGI programs.0. see the LiveWire Developer's Guide. JavaScript 1. multiple clients. JavaScript supports a runtime system based on a small number of data types representing numeric.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. and grammar Rules for expressions. This process is illustrated in the following figure. LiveWire JavaScript contains an object framework that you can use to maintain data that persist across client requests. Different versions of JavaScript work with specific versions of Navigator. and string values. The JavaScript language resembles Java but does not have Java's static typing and strong type checking. client and server JavaScript differ in numerous ways.

Cannot automatically write to hard disk. By specifying a file as the JavaScript source (rather than embedding the JavaScript in the HTML).. HTML. Type safety means. Variable data types not declared (loose typing). specialized builtin functionality. and embedded in. By specifying a JavaScript expression as the value for an HTML attribute. See "Scripting event handlers". These requirements make Java programming more complex than JavaScript authoring. Functions can be properties of objects. Java Compiled bytecodes downloaded from server.. Applets distinct from HTML (accessed from HTML pages). Cannot automatically write to hard disk. Java's class inheritance and strong typing generally require tightly coupled object hierarchies. As event handlers within certain other HTML tags (mostly form elements). executing as loosely typed methods. Variable data types must be declared (strong typing). Dynamic binding.htm (3 of 16) [30/08/2003 9:33:59 PM] . See "Specifying a file of JavaScript code". but no classes Object-oriented. </SCRIPT> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. and minimal requirements for object creation. executed on client. Java's objectoriented model means that programs consist exclusively of classes and their methods. "Using the SCRIPT tag". These scripting languages offer programming tools to a much wider audience because of their easier syntax.htm simple. Uses built-in. JavaScript is case sensitive. instance-based object model that still provides significant capabilities. JavaScript also supports functions without any special declarative requirements. Embedding JavaScript in HTML You can embed JavaScript in an HTML document in the following ways: q q q q As statements and functions within a <SCRIPT> tag.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. Java is an object-oriented programming language designed for fast execution and type safety. In contrast. Using the SCRIPT tag The <SCRIPT> tag is an extension to HTML that can enclose any number of JavaScript statements as shown here: <SCRIPT> JavaScript statements. inheritance. Object-based. for instance. Object references must exist at compile-time. Unlike HTML. See the following section. JavaScript Interpreted (not compiled) by client. Object references checked at runtime. that you can't cast a Java integer into an object reference or access private memory by corrupting Java bytecodes. Static binding. Code integrated with. See "Using JavaScript expressions as HTML attribute values". JavaScript descends in spirit from a line of smaller. extensible objects. Applets consist of object classes with or inheritance. dynamically typed languages like HyperTalk and dBASE.

once for JavaScript 1. and these scripts will not cause errors if run under Navigator 2.> . Navigator 3.1"> // Redefine those functions using 1.1-only functions </SCRIPT> <FORM . one for JavaScript 1. . Example 1. and once using JavaScript 1.0.0..0 assumes LANGUAGE="JavaScript1.1"> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart.0.0 executes code within the <SCRIPT LANGUAGE="JavaScript"> tag. The default document that loads is for JavaScript 1. This example shows how to define functions twice.0 executes JavaScript code within either the <SCRIPT LANGUAGE="JavaScript"> or <SCRIPT LANGUAGE="JavaScript1. and each can enclose any number of JavaScript statements. Navigator 2.1 features.htm A document can have multiple SCRIPT tags. for example: q q Navigator 2.0. Navigator 3. <SCRIPT LANGUAGE="JavaScript1..0-compatible functions such as doClick() here </SCRIPT> <SCRIPT LANGUAGE="JavaScript1. </SCRIPT> JavaScriptVersion specifies one of the following to indicate which version of JavaScript your code is written for: q q <SCRIPT LANGUAGE="JavaScript"> specifies JavaScript for Navigator 2.1"> tag.1.1"> specifies JavaScript for Navigator 3. This example shows how to use two separate versions of a JavaScript document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. the replace method replaces the page. Specifying the JavaScript version The optional LANGUAGE attribute specifies the scripting language and JavaScript version: <SCRIPT LANGUAGE="JavaScriptVersion"> JavaScript statements.. it ignores code within the <SCRIPT LANGUAGE="JavaScript1.0. <SCRIPT LANGUAGE="JavaScript1.> <INPUT TYPE="button" onClick="doClick(this)" .. If the LANGUAGE attribute is omitted. If the user is running Navigator 3.0 features. The following examples show some techniques for using the LANGUAGE attribute.1" You can use the LANGUAGE attribute to write scripts that contain Navigator 3.0 and one for JavaScript 1.0.1"> tags. <SCRIPT LANGUAGE="JavaScript"> // Define 1. .0 assumes LANGUAGE="JavaScript".. Statements within a <SCRIPT> tag are ignored if the user's browser does not have the level of JavaScript support specified in the LANGUAGE attribute. </FORM> Example 2.htm (4 of 16) [30/08/2003 9:33:59 PM] .1 features // Also define 1..

Begin to hide script contents from old browsers. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart.1 by comparing new properties (such as navigator. <SCRIPT LANGUAGE="JavaScript"> if (navigator. non-JavaScript-capable browsers will ignore the beginning and ending SCRIPT tags.0 and later recognize JavaScript.0.. because the examples are written specifically for Navigator 2. some of the examples in this book do not hide scripts.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart.0 and Java is enabled. so the 1.0-compatible page continues here.indexOf("3. so they are ignored too.1/mypage.. no Java connection } Hiding scripts within comment tags Only Netscape Navigator versions 2.1.. The code then conditionally executes 1.0. place the entire script within HTML comment tags.userAgent. To ensure that other browsers ignore JavaScript code. --> </SCRIPT> Since browsers typically ignore unknown tags.htm (5 of 16) [30/08/2003 9:33:59 PM] . JavaScript statements.1 features.0. an undefined property compares equal to null.0" </SCRIPT> [hereafter. Note For simplicity.0 and 1.javaEnabled != null && navigator.replace("js1. All the script statements in between are enclosed in an HTML comment.userAgent property to determine whether the user is running Navigator 3.0 and 1.] Example 3.1 extensions] Example 4.html") </SCRIPT> [1.0. // End the hiding here.1 function references will be non-null in Navigator 3.htm // Replace this page in session history with the 1.1" else jsVersion = "1. test jsVersion == "1. This example shows how to test the navigator.focus) to null. and precede the ending comment tag with a double-slash (//) that indicates a JavaScript single-line comment: <SCRIPT> <!-. } else { // 2. Navigator properly interprets the SCRIPT tags and ignores the line in the script beginning with the double-slash (//). use LiveConnect here.. you can test the differences between JavaScript 1.. it is considered good etiquette so that your pages don't generate unformatted script statements for those not using Navigator 2.0 or later. if (navigator. In JavaScript 1. In many cases. Although you are not required to use this technique.1" before use of any 1..javaEnabled or window.javaEnabled()) { // must be 3.1 version location.0") != -1) jsVersion = "1.

js.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart.com/functions/jsfuncs.netscape. which are discussed in "Scripting event handlers". External JavaScript files should have the file name suffix . semicolons are optional and are required only if you want to put more than one statement on a single line.. </SCRIPT> </HEAD> <BODY> .. folks. You may sometimes see a semicolon at the end of each line of JavaScript.js"> . </BODY> </HTML> This script displays the following in Navigator: Hello. folks.htm (6 of 16) [30/08/2003 9:33:59 PM] . document. --> </SCRIPT> <P>That's all. and the server must map the . net!") // End the hiding here. generated with plain HTML. generated with JavaScript. net! That's all. This is most useful in defining event handlers.. Notice that there is no difference in appearance between the first line. you might want to put the following statement between the <SCRIPT SRC=".. JavaScript statements within a <SCRIPT> tag with a SRC attribute are ignored unless the inclusion has an error. This attribute is especially useful for sharing functions among many different pages.js suffix to the MIME type file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart.js"> External JavaScript files cannot contain any HTML tags: they must contain only JavaScript statements and function definitions. The closing </SCRIPT> tag is required. For example. For example: <SCRIPT SRC="http://home.write("Hello.."> and </SCRIPT> statements: document. For example: <HEAD> <TITLE>My Page</TITLE> <SCRIPT SRC="common. Specifying a file of JavaScript code The SRC attribute of the <SCRIPT> tag lets you specify a file as the JavaScript source (rather than embedding the JavaScript in the HTML). relative or absolute.htm Example: a first script Here is a simple script: <HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!--.write("Included JS file not found") The SRC attribute can specify any URL. In general. and the second line..Hide script from old browsers.

Note however. which the server sends back in the HTTP header. suppose you define a variable barWidth. For example. You can use JavaScript entities only where an HTML attribute value would normally go.</H4> would display myTitle rather than the value of the variable myTitle. Navigator will not load the JavaScript file specified by the SRC attribute properly. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. Entity values are evaluated dynamically.js filename suffix to "application/x-javascript" MIME type.htm "application/x-javascript". JavaScript entities also start with an ampersand (&) and end with a semicolon (. The following example shows a <NOSCRIPT> tag. To map the suffix to the MIME type. add the following line to the mime. the display of a page can change only if you reload the page.htm (7 of 16) [30/08/2003 9:33:59 PM] . type=application/x-javascript exts=js If the server does not map the . if barWidth were 50.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. Navigator displays the code within the <NOSCRIPT> tag.%" ALIGN="LEFT"> So. for example. that if the user has disabled JavaScript by choosing Network Preferences from the Options menu. HTML enclosed within a <NOSCRIPT> tag is displayed by browsers that do not support JavaScript. This allows you to create more flexible HTML constructs. code within the tag is ignored by Navigator. because the attributes of one HTML element can depend on information about elements placed previously on the page. For example. You may already be familiar with HTML character entities by which you can define characters with special numerical codes or names by preceding the name with an ampersand (&) and terminating it with a semicolon (. For example. this would create the following display: As with other HTML. you can specify a JavaScript expression as the value for an HTML attribute. <H4>&{myTitle}. you can include a greater-than symbol (>) with the character entity &GT. JavaScript entities will be interpreted only on the right-hand side of HTML attribute name/value pairs. Unlike regular entities which can appear anywhere in the HTML text flow.). and a less-than symbol (<) with &LT. after layout has occurred. you use a JavaScript expression enclosed in curly braces {}.types file in the server's config directory. Note This requirement does not apply if you are using local files. Specifying alternate content with the NOSCRIPT tag Use the <NOSCRIPT> tag to specify alternate content for browsers that do not support JavaScript.). Using JavaScript expressions as HTML attribute values Using JavaScript entities.. Instead of a name or number. and then restart the server. You could create a horizontal rule with the specified percentage width as follows: <HR WIDTH="&{barWidth}.

That way. the user might perform an action while the page is still loading that triggers an event handler and calls an undefined function. leading to an error. A function definition has these basic parts: q q q q The function keyword.0 or later. so you need to get Netscape Navigator 2.netscape. you should enable JavaScript by choosing Network Preferences from the Options menu. A function is a JavaScript procedure--a set of statements that performs a specific task.0 or later! <BR> <A HREF="http://home. A comma-separated list of arguments to the function in parentheses. Functions are one of the fundamental building blocks in JavaScript.htm <NOSCRIPT> <B>This page uses JavaScript.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. It's important to understand the difference between defining and calling a function. Otherwise. you should define the functions for a page in the HEAD portion of a document. see "Functions". Defining the function simply names the function and specifies what to do when the function is called. A function name. The following example defines a simple function in the HEAD of a document and then calls it in the BODY of the document: <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-.gif"></A> If you are using Navigator 2.htm (8 of 16) [30/08/2003 9:33:59 PM] .. Defining and calling functions For a complete description of defining and calling functions.com/comprod/mirror/index. Event handlers are introduced in "Scripting event handlers". and you see this message.Hide script from old browsers function square(number) { return number * number } // End script hiding from old browsers --> </SCRIPT> </HEAD> <BODY> <SCRIPT> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. The statements in the function in curly braces.html"> <IMG SRC="NSNow. Calling the function actually performs the specified actions with the indicated parameters.. all functions are defined before any content is displayed. </NOSCRIPT> . Generally.

In the BODY of the document. A method is a function associated with an object." But right now. "HTML already does that. You can also use the string file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart.. The function executes its statements and returns the value twenty-five. you can display text conditionally or based on variable arguments. The script displays the following results: The function returned 25.write(." But in a script you can do all kinds of things you can't do with ordinary HTML. For example. For these reasons.. you can also define Function objects. square(5). methodName is the name of the method. In addition to defining functions as described here. Using the write method As you saw in the previous example.") </SCRIPT> <P> All done. "Object model. write is one of the most often-used JavaScript methods. The write method takes any number of string arguments that can be string literals or variables. as described in "Function object".methodName(arguments. ". the statement square(5) calls the function with an argument of five..htm document.write("The function returned ". The function consists of one statement return number * number that indicates to return the argument of the function multiplied by itself. You'll learn more about objects and methods in Chapter 8. the write method of document displays output in the Navigator. The square function used the line document." you say. because it is particularly useful.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart.) to display output in Navigator. we will explore write a little more.) where objectName is the name of the object. "Big deal. separated by commas. called number.. and arguments is a list of arguments to the method. This line calls the write method of the Navigator document object with JavaScript's standard object notation: objectName.htm (9 of 16) [30/08/2003 9:33:59 PM] . The return statement specifies the value returned by the function. </BODY> The function square takes one argument. All done.

"Using JavaScript is easy.hide script from old browsers bar(25) output(2... which generates dynamic HTML with Navigator JavaScript: <HEAD> <SCRIPT> <!--.write("<HR ALIGN='left' WIDTH=". ">". and paragraph text specified by the third argument. Consider the following script. heading text specified by the second argument. which displays an HTML horizontal rule of a width specified by the function's argument. "</H".Hide script from old browsers // This function displays a horizontal bar of specified width function bar(widthPct) { document. headText.write("<HR ALIGN='left' WIDTH=" + widthPct + "%>") } // This function displays a heading of specified level and some text function output(headLevel.htm (10 of 16) [30/08/2003 9:33:59 PM] . text) } // end script hiding from old browsers --> </SCRIPT> </HEAD> <BODY> <SCRIPT> <!--. output.write("<H". The document BODY then calls the two functions to produce the following display: The following line creates the output of the bar function: document. headLevel.htm concatenation operator (+) to create one string from several when using write.") // end script hiding from old browsers --> </SCRIPT> <P> This is some standard HTML. </BODY> The HEAD of this document defines two functions: q q bar. text) { document. "%>") file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. "JavaScript Rules!". widthPct. "><P>". which displays an HTML heading of the level specified by the first argument. unlike the above that is generated.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. headLevel. headText.

0. you cannot change it without reloading the page. For example. there is no difference between write and writeln except inside tags such as PRE. such as onChange and onClick. Events are actions that occur usually as a result of something the user does. You must do this whenever you want to indicate a quoted string inside a string literal. clicking a button is an event. Displaying output JavaScript in Navigator generates its results from the top of the page down. For example. writeln. Printing output Navigator 3. the user must specify the view-source: protocol. as is changing a text field or moving the mouse over a hyperlink. Each event is recognized by certain objects (HTML tags). depending on the platform) at the end of its output. In general. For more information. To view HTML code that was generated with JavaScript write and writeln methods.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. see "Example: using an event handler".0 prints output created with JavaScript.html Navigator 2. which respect carriage returns. Scripting event handlers JavaScript applications in the Navigator are largely event-driven. "Using windows and frames. Because HTML generally ignores newlines. see Chapter 3." Form elements without reloading the page. does not print output created with JavaScript. Once text has been displayed. You can define event handlers.htm (11 of 16) [30/08/2003 9:33:59 PM] . you can update q q A "subwindow" in a frame separately. The following example shows a view-source: URL: view-source:wysiwyg://0/file:/c|/temp/genhtml. which adds a newline sequence (a carriage return or a carriage return and linefeed.htm Notice that the definition of bar uses single quotation marks inside double quotation marks. to make your script react to events.. If the user chooses Document Source or Frame Source from the View menu. summarized in the following table: Event Applies to Occurs when Event handler file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart." even though you see both lines onscreen. the content displayed is that of the wysiwyg: URL. you see only the line that reads "This is some standard HTML. the user chooses Print from the File menu. Then the call to bar with an argument of twenty-five produces output equivalent to the following HTML: <HR ALIGN="left" WIDTH=25%> write has a companion method.. However. To print output.. you cannot update part of a page without updating the entire page. if the user chooses Print from the File menu to print the page in the previous example.

links text fields. It makes your code easier to read. textareas. or form element User loads the page in the Navigator User moves mouse pointer out of an area (client-side image map) or link User moves mouse pointer over a link User resets a form (clicks a Reset button) User selects form element's input field User submits a form User exits the page mouseout areas. textareas submit button document body If an event applies to an HTML tag. Notice in the preceding example this.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. then you can define an event handler for it. preceded by "on. The general syntax is <TAG eventHandler="JavaScript Code"> where TAG is an HTML tag and eventHandler is the name of the event handler. suppose you have created a JavaScript function called compute.htm abort images User aborts the loading of an image (for onAbort example by clicking a link or clicking the Stop button) User removes input focus from window. The onClick event handler is a call to the compute function.form then refers to the form containing the button. it is good practice to define functions for your event handlers: q q It makes your code modular--you can use the same function as an event handler for many different items.Over onReset onSelect onSubmit onUnload blur click change error focus load windows. with the current form as the argument. If you want to include more than one statement. User clicks form element or link reset buttons. and all form elements document body User changes value of element The loading of a document or image causes an error User gives input focus to window. which is the button. add an event handler attribute to the tag. links mouseover links reset select submit unload forms text fields. radio buttons.form refers to the current form.htm (12 of 16) [30/08/2003 9:33:59 PM] . frame. frames. submit buttons. For example. or form element onBlur onClick onChange onError onFocus onLoad onMouseout onMouse. select lists images. The keyword this refers to the current object. frames. These statements are executed when the user clicks the button.form)"> You can put any JavaScript statements inside the quotation marks following onClick. You can cause Navigator to perform this function when the user clicks a button by assigning the function call to the button's onClick event handler: <INPUT TYPE="button" VALUE="Calculate" onClick="compute(this. The name of an event handler is the name of the event. The construct this. checkboxes. Put JavaScript code in quotation marks as the attribute value. In general. the event handler for the focus event is onFocus. separate statements with a semicolon (. frame. and all form elements buttons. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. To create an event handler for an HTML tag." For example. windows windows.).

and then click the button.Hide script from old browsers function compute(f) { if (confirm("Are you sure?")) f.form)"> <BR> Result: <INPUT TYPE="text" NAME="result" SIZE=15 > </FORM> </BODY> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart.htm (13 of 16) [30/08/2003 9:33:59 PM] . Because event handlers in HTML must be enclosed in quotation marks.expr. you must use single quotation marks to delimit string arguments. the function bar contains the literal "left" within a double-quoted attribute value: function bar(widthPct) { document. <HEAD> <SCRIPT> <!--. The second text field then displays the value of the expression (for example. 4).html'.value = eval(f.value) else alert("Please come back again. 2 + 2) in the first text field. 'newWin')"> </FORM> Example: using an event handler In the following example.") } // end hiding from old browsers --> </SCRIPT> </HEAD> <BODY> <FORM> Enter an expression: <INPUT TYPE="text" NAME="expr" SIZE=15 > <INPUT TYPE="button" VALUE="Calculate" onClick="compute(this.result. In the following example.write("<HR ALIGN='left' WIDTH=" + widthPct + "%>") } Here's another example: <INPUT TYPE="button" VALUE="Press Me" onClick="myfunc('astring')"> Be sure to alternate double quotation marks with single quotation marks.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. For example: <FORM NAME="myform"> <INPUT TYPE="button" NAME="Button1" VALUE="Open Sesame!" onClick="window.open('mydoc.htm Using quotation marks Use single quotation marks ( ' ) to delimit string literals so that scripts can distinguish the literal from attribute values enclosed in double quotation marks. you can enter an expression (for example.

taking one argument.. you must spell event handler names in lowercase in JavaScript. <SCRIPT LANGUAGE="JavaScript"> function fun1() { .0. The form contains a button with an onClick event handler that calls the compute function.. If the user clicks OK.form that denotes the current Form object. If the user clicks Cancel. When the user clicks the button. } </SCRIPT> <FORM NAME="myForm"> <INPUT TYPE="button" NAME="myButton" onClick="fun1()"> </FORM> <SCRIPT> document.value). since the event handler HTML attributes are literal function bodies. so you must assign fun2.onclick=fun2 </SCRIPT> Note that event handlers are function references. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. compute. then confirm returns false and the alert method displays another message. not fun2() (the latter calls fun2 and has whatever type and value fun2 returns). which is a Form object. Calculate Calling event handlers explicitly In JavaScript for Navigator 3. In compute. as in the example... Also. JavaScript calls compute with the argument this. then confirm returns true. The function uses the Navigator JavaScript method confirm to display a Confirm dialog box with OK and Cancel buttons. as shown in the following example. you can reset an event handler specified by HTML.htm (14 of 16) [30/08/2003 9:33:59 PM] . because JavaScript is case-sensitive. which can be any string representing any JavaScript expression or statements.htm The display in Navigator will look like this: Enter an expression: Result: The HEAD of the document defines a single function.expr. this form is referred to as the argument f.myButton. Finally.myForm.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. } function fun2() { . you cannot use <INPUT onClick=fun1> in the HTML source to make fun1 the onClick handler for an input. f. you must call fun1 instead. The built-in JavaScript function eval evaluates its argument. and the value of the result text field is set to the value of eval(f.

It reduces delays in case of user error. Order Cannot Be Submitted!") return false } } file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. so data must travel from client to server. you'll want to validate input in (at least) two places: q q As the user enters it.quantity. 999)) { alert("Order has been Submitted") return true else { alert("Sorry.htm Validating form input If you can't run server-based programs.name + " less than " + max) function validateAndSubmit(theform) { if (qty_check(theform. skip this section.name + " greater than " + min) max) " + item. It simplifies the server-based program. and then returned to client for valid input. Example validation functions The following are some simple validation functions. When the user submits the form. One of the most important uses of JavaScript is to validate form input to server-based programs such as LiveWire applications or CGI programs. This is useful because q q q It reduces load on the server. 0. <HEAD> <SCRIPT LANGUAGE="javascript"> function isaPosNum(s) { return (parseInt(s) > 0) } function qty_check(item. with an onChange event handler on each form element that you want validated.value) alert("Please enter else returnVal = true return returnVal } a < a > a postive number" ) min) " + item. Generally. Validation otherwise has to be performed on the server. "Bad data" are already filtered out when input is passed to the server-based program.value)) alert("Please enter else if (parseInt(item. with an onClick event handler on the button that submits the form.htm (15 of 16) [30/08/2003 9:33:59 PM] . be processed.value) alert("Please enter else if (parseInt(item.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. min. max) { var returnVal = false if (!isaPosNum(item.

<INPUT TYPE="submit" onSubmit="return qty_check(theform. Notice that both event handlers use this to represent the current object: in the text field. You can also use a submit button (defined by <INPUT TYPE="submit">) with an onSubmit event handler that returns false if the data are not valid. 0. and false otherwise. if the data are valid.htm </SCRIPT> </HEAD> isaPosNum is a simple function that returns true if its argument is a positive number. the onSubmit handler will prohibit the form from being submitted. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. the BODY of the document uses qty_check as an onChange event handler for a text field and validateAndSubmit as the onClick event handler for a button. this example uses a button that calls validateAndSubmit. <BODY> <FORM NAME="widget_order" ACTION="lwapp.quantity. validateAndSubmit takes a Form object as its argument. it uses qty_check to check the value of the form element and submits the form if the input value is valid. 999)" When qty_check returns false if the data are invalid. The form looks like this: How many widgets today? Enter Order The onChange event handler is triggered when you change the value in the text field and move focus from the field by either pressing the Tab key or clicking the mouse outside the field. and in the button it is used to pass the JavaScript Form object to validateAndSubmit. It also could be used to submit the form to a CGI program. it is used to pass the JavaScript object corresponding to the text field to qty_check. it displays an alert and does not submit the form.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/getstart. Using the validation functions In this example. Otherwise. For example. qty_check takes three arguments: an object corresponding to the form element being validated (item) and the minimum and maximum allowable values for the item (min and max).form)"> </FORM> </BODY> This form submits the values to a page in a LiveWire application called lwapp. which submits the form using the submit method. 999)"> <BR> <INPUT TYPE="button" VALUE="Enter Order" onClick="validateAndSubmit(this.htm (16 of 16) [30/08/2003 9:33:59 PM] . To submit the form to the server-based program.html. 0.html" METHOD="post"> How many widgets today? <INPUT TYPE="text" NAME="quantity" onChange="qty_check(this. It checks that the value of item is a number between min and max and displays an alert if it is not.

For example. an object's "descendants" are properties of the object. to distinguish them from LiveWire objects or user-defined objects. see Appendix A. it is useful to understand the Navigator JavaScript object hierarchy. "Object summary. methods. Navigator object hierarchy When you load a document in Navigator. In the strict object-oriented sense. as you can in languages such as Java.htm (1 of 10) [30/08/2003 9:33:59 PM] . this type of hierarchy is known as an instance hierarchy. For a list of all objects and their properties. and event handlers. it creates a number of JavaScript objects with property values based on the HTML in the document and other pertinent information.form1. The Navigator object hierarchy is illustrated in the following figure." file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj. These client-side JavaScript objects are sometimes referred to as Navigator objects. Although you cannot derive object classes from JavaScript objects. a form named form1 is an object as well as a property of document. because it concerns specific instances of objects rather than object classes. and is referred to as document.htm Using Navigator objects his chapter describes JavaScript objects in Navigator and how to use them. In this hierarchy. These objects exist in a hierarchy that reflects the structure of the HTML page itself.

aircraft. has properties that apply to the entire window." For example.aircraft. Generally. each form (defined by a FORM tag) in the document will have a corresponding Form object. That is. document has a property for each form and each anchor in the document.value. the following refers to the value property of a text field named text1 in a form named myform in the current document. If an object is on a form. see Chapter 3. images do not need to be on a form. and for the plug-ins installed on the client. For instance. even if the object does not need to be on a form.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj.imageForm. For example. document: contains properties based on the content of the document. The following code refers to an image that is on a form: document. you must include the form name when referring to that object. such as title. and forms.src='f15e. location: has properties based on the current URL. For example. the document may contain other objects.src='f15e. history: contains properties representing URLs the client has previously requested. links. For more information and examples. they are created based on the HTML in the document. Depending on its content.htm (2 of 10) [30/08/2003 9:34:00 PM] . background color.text1. "Using windows and frames.htm Every page has the following objects: q q q q q navigator: has properties for the name and version of the Navigator being used. you must specify the object name and all its ancestors. an object gets its name from the NAME attribute of the HTML tag.myform. for the MIME types supported by the client. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj. There is also a window object for each "child window" in a frames document.gif' The following code refers to an image that is not on a form: document. document. window: the top-level object. To refer to specific properties.gif' document properties: an example The properties of the document object are largely content-dependent.

htm Suppose you create a page named simple. The values for document.fgColor #000000 document. the basic objects would have properties like those shown here: Property document.href history.propertyName So.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj.title reflects the value specified in the TITLE tag. so they are based on the default values specified in the Preferences dialog box (when the user chooses General Preferences from the Options menu). given the preceding HTML example.bgColor (the background color) were not set in the HTML.form)"> Option #1 <P> <INPUT TYPE="button" NAME="button1" VALUE="Press Me" onClick="update(this. JavaScript uses the following object notation: objectName.cgi" METHOD="get" >Enter a value: <INPUT TYPE="text" NAME="text1" VALUE="blahblah" SIZE=20 > Check if you want: <INPUT TYPE="checkbox" NAME="Check1" CHECKED onClick="update(this.htm (3 of 10) [30/08/2003 9:34:00 PM] .title Value "A Simple Document" document.html" 7 Notice that the value of document.bgColor #ffffff location.length "http://www.sampson.fgColor (the color of text) and document.com/samples/simple.form)"> </FORM> </BODY> As you saw in the previous chapter.html that contains the following HTML: <HEAD><TITLE>A Simple Document</TITLE> <SCRIPT> function update(form) { alert("Form being updated") } </SCRIPT> </HEAD> <BODY> <FORM NAME="myform" ACTION="foo. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj.

based on the Navigator object hierarchy. for example.htm Because there is a form in the document. for example. followed by the name of the form. there is also a Form object called myform (based on the form's NAME attribute) that has child objects for the checkbox and the button.button1. q q q q button1. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj.myform. finally. q q q document. button1.value is "blahblah" text1. the property name." based on the value of the METHOD attribute. as follows: These are the full names of the objects.myform. the button Thus. document.myform.value is "Press Me" button1.htm (4 of 10) [30/08/2003 9:34:00 PM] . layout happens sequentially in the Navigator: the Navigator starts at the top of the HTML file and works downward. for example.button1.Check1. the Form object myform has properties based on the attributes of the FORM tag.sampson. sometimes referred to as reflection because the property values reflect the HTML. the form document. q q q action is http://www. starting with document. because there are three input elements in the form.cgi. corresponding to the button and text field in the form. To understand JavaScript reflection. length is 3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj. Each of these objects has a name based on the NAME attribute of the HTML tag that defines it. then the element name. This full name is based on the Navigator object hierarchy. myform. These objects have their own properties based on their HTML attribute values.name is "text1" In practice.name is "Button1" text1. Generally. displaying output to the screen as it goes.myform.value.com/samples/foo. and. The Form object has child objects named button1 and text1. JavaScript reflection and HTML layout JavaScript object property values are based on the content of your HTML document. it is important to understand how the Navigator performs layout--the process by which Navigator transforms HTML tags into graphical display on your computer. the URL to which the form is submitted. the checkbox document. Because of this "top-down" behavior. method is "get. you refer to these properties using their full names.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj.Updated!" to the value.title = "The New Improved JavaScript Page" There are some important exceptions to this rule: you can update the value of form elements dynamically. once layout has occurred.Age.mytext. For example.value += '.statform.write(document.userName." Each time you click the button. Likewise. For example.title. <FORM NAME="demoForm"> <INPUT TYPE="text" NAME="mytext" SIZE="40" VALUE="Starting Value"> <P><INPUT TYPE="button" VALUE="Click to Update Text Field" onClick="document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj. you add the text ".. or generate an error.value) document..htm (5 of 10) [30/08/2003 9:34:00 PM] .write(document. Once the Navigator has displayed this in the title bar of the Navigator window..value) </SCRIPT> However. because the objects don't exist yet in the Navigator. it will not change the value of document.userName and document. For example.statform. suppose you have a document title defined as follows: <TITLE>My JavaScript Page</TITLE> This is reflected in JavaScript as the value of document. the following script defines a text field that initially displays the string "Starting Value.statform. if you tried to do this before the form definition (above it in the HTML page).title.demoForm. For example. you cannot change the value in JavaScript. document.. affect the appearance of the page. setting a property value does not affect its value or appearance.statform.htm JavaScript reflects only HTML that it has encountered. you would get an error.Age. If you have the following script later in the page.Updated!' "> </FORM> This is a simple example of updating a form element after layout. you could display the value of these objects in a script after defining the form: <SCRIPT> document. suppose you define a form with a couple of text-input elements: <FORM NAME="statform"> <INPUT TYPE = "text" name = "userName" size = 20> <INPUT TYPE = "text" name = "Age" size = 3> These form elements are reflected as JavaScript objects that you can use after the form is defined: document.

window also has two properties you can set to perform useful tasks: location and status.bgcolor. you can specify the size of the window. and other "chrome" attributes. You can set location to redirect the client to another URL.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj. the following statement redirects the client to the Netscape home page. Key Navigator objects This section describes some of the most useful Navigator objects. you can also change a few other properties after layout has completed. location. "Reference. Frame objects have the same properties and methods as window objects and differ only in the way they are displayed. Form. For more detailed information on these objects.netscape. see the corresponding reference topics in Part 3.htm Using event handlers." window and Frame objects For more information on windows and frames. For example. prompt: Displays a Prompt dialog box with a text field for entering a value. including window.htm (6 of 10) [30/08/2003 9:34:00 PM] . or gives focus to a window. setTimeout: Evaluates an expression after the specified time. A Frame object is defined by the FRAME tag in a FRAMESET document. its content. as if the user had clicked a hyperlink or otherwise loaded the URL: location = "http://home. You can create multiple windows in a Navigator JavaScript application. for example. confirm: Displays a Confirm dialog box with OK and Cancel buttons. and whether it has a button bar. "Using windows and frames. document." The window object is the "parent" object for all other objects in Navigator.com" file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj. blur and focus: Removes focus from. and history objects. scroll: Scrolls a window to a specified coordinate. Frame. alert: Displays an Alert dialog box with a message. location field. The window object has numerous useful methods: q q q q q q q open and close: Opens and closes a browser window. document. see Chapter 3.

The document object has a number of properties that reflect the colors of the background. Link. In the following example. and URL. radio buttons. Other useful document properties include lastModified. Form object Each form in a document creates a Form object. document object Because its write and writeln methods generate HTML. Applet. fgColor.htm (7 of 10) [30/08/2003 9:34:00 PM] . the date the document was last modified. users can print and save generated HTML. This property is especially useful in event handlers.0. the form myForm contains a Text object and a button. are stored in an elements array. Area. the URL of the document. the elements in a form. See "write". Form. where you might need to refer to another element on the current form. myForm.htm You can use the status property to set the message in the status bar at the bottom of the client window. and so on. for more information. referrer. and links in the page: bgColor. text. Form objects are stored in an array called forms. the document object is one of the most useful Navigator objects.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj. The cookie property enables you to get and set cookie values. by using the commands on the File menu. and Plugin objects in the page. So you could refer to the first element (regardless of what it is) in the first form as document. for more information. When the user clicks the button. The document object is the ancestor for all the Anchor. linkColor. In Navigator 3. A page has only one document object. see "Using cookies". and so on.forms[0] Likewise. see "Using the status bar". alinkColor. and vlinkColor. the second forms[1]. In addition to referring to each form by name. The button's onClick event handler uses this. the previous URL the client visited. Because a document can contain more than one form. Image. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj. the value of the Text object is set to the form's name. you can refer to the first form in a document as document. such as text fields.elements[0] Each form element has a form property that is a reference to the element's parent form.forms[0].form to refer to the parent form. The first form (topmost in the page) is forms[0].

go(0) The history list is displayed in the Navigator Go menu.form. You can also redirect the client to any history entry by using the go method.name"> </FORM> location object The location object has properties based on the current URL.value=this. You can access the other history values using the history array. navigator object The navigator object contains information about the version of Navigator in use.go(-2) The following code reloads the current page: history. next. and the appVersion property specifies version file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj. next. You can access the current. each array entry is a string containing a URL. history. history object The history object contains a list of strings representing the URLs the client has visited.htm (8 of 10) [30/08/2003 9:34:00 PM] . For example. the following code loads the URL that is two entries back in the client's history list. The location object has two methods: q q reload forces a reload of the window's current document. replace loads the specified URL over the current history entry.htm <FORM NAME="myForm"> Form name:<INPUT TYPE="text" NAME="text1" VALUE="Beluga"> <P> <INPUT NAME="button1" TYPE="button" VALUE="Show Form Name" onClick="this. the hostname property is the server and domain name of the server hosting the document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj.text1. and previous history entries by using the history object's current. the appName property specifies the name of the browser. and previous properties. This array contains an entry for each history entry in source order. For example. For example.form.

0. In Navigator 3. For example. you can index arrays by either their ordinal number or their name (if defined). you must index arrays by their ordinal number.. and Link objects created with the link method in source order arguments Reflects all the arguments to a function mimeTypes Reflects all the MIME types supported by the client (either internally. for example document. Radio."> tags.0.htm (9 of 10) [30/08/2003 9:34:00 PM] . if the second <FORM> tag in a document has a NAME attribute of "myForm". and Text objects) in source order Reflects a document's <EMBED> tags in source order Reflects a document's <FORM> tags in source order Reflects all the <FRAME> tags in a window containing a <FRAMESET> tag in source order Reflects a window's history entries Reflects a document's <IMG> tags in source order (images created with the Image() constructor are not included in the images array) Reflects a document's <AREA HREF=". you can refer to file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj. Navigator's object arrays Navigator has the following predefined arrays: Array anchors applets elements embeds forms frames history images links Description Reflects all the <A> tags containing a NAME attribute in a document in source order Reflects all the <APPLET> tags in a document in source order Reflects a form's elements (such as Checkbox.forms[0]. taintEnabled specifies whether data tainting is enabled. The navigator object has two methods: q q javaEnabled specifies whether Java is enabled. <A HREF=""> tags. or by plug-ins) options plugins Reflects all the options in a Select object (<OPTION> tags) in source order Reflects all the plug-ins installed on the client in source order In Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj..htm information for the Navigator. via helper applications.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj.forms[1] or document. suppose the following form element is defined: <INPUT TYPE="text" NAME="String|Comments"> If you need to refer to this form element by name. For example.htm the form as document. you can specify document.forms["String|Comments"].forms["myForm"] or document.htm (10 of 10) [30/08/2003 9:34:00 PM] . file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/navobj.myForm.

The following statement creates a window called msgWindow that displays the contents of the file sesame."displayWindow") A window name is not required when you create a window. the second name.open ("sesame. you can open another window by choosing New Web Browser from the File menu.open("sesame. or scrollbars. methods. displayWindow. refers to the window as the target of a form submit or hypertext link."displayWindow". refers to the window's properties. But the window must have a name if you want to refer to it from another window. You can also open and close windows programmatically with JavaScript.html: msgWindow=window. location field. you can specify attributes such as the window's height and width and whether the window contains a toolbar. The window object is the top-level object in the JavaScript client hierarchy. but correspond to "sub-windows" created with the FRAME tag in a FRAMESET document.html". Opening and closing windows A window is created automatically when you launch Navigator. The following statement creates a window without a toolbar but with scrollbars: msgWindow=window."toolbar=no. The first name. When you open a window.open("http://home.html") The following statement creates a window called homeWindow that displays the Netscape home page: homeWindow=window.htm (1 of 9) [30/08/2003 9:34:00 PM] . The following statement creates a window with two names. and containership. msgWindow.scrollbars=yes") file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. see "Referring to windows and frames".netscape. Frame objects are similar to window objects. msgWindow=window. You can close a window by choosing either Close or Exit from the File menu.html".open("sesame.htm Using windows and frames avaScript lets you create and manipulate windows and frames for presenting HTML content. Windows can have two names. Opening a window You can create a window with the open method.com") For more information on window names.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows.

all within the same window. Frames can point to different URLs and be targeted by other URLs.htm (2 of 9) [30/08/2003 9:34:00 PM] .close() self.htm For details on these window attributes. each with its own distinct URL.close() Using frames A frame is a special type of window that can display multiple. independently scrollable frames on a single screen. see the reference topic for the open (window object) method. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. A series of frames. makes up a page. or a frameset. the frame on the bottom is named navigateFrame. You cannot close a frame without closing the entire parent window. The frame on the left is named listFrame. the frame on the right is named contentFrame. The following depicts a window containing three frames. Each of the following statements closes the current window: window. Closing a window You can close a window with the close method.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows.close() // Do not use the following statement in an event handler close() The following statement closes a window called msgWindow: msgWindow.

and a frame.htm (3 of 9) [30/08/2003 9:34:00 PM] .htm Creating a frame You create a frame by using the FRAMESET tag in an HTML document.html NAME="listFrame"> <FRAME SRC=titles. The following statement creates the frameset shown previously: <FRAMESET ROWS="90%. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. Example 1.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. This is because a frame's parent is its parent window.html NAME="navigateFrame"> </FRAMESET> The following diagram shows the hierarchy of the frames.70%"> <FRAME SRC=category. this tag's sole purpose is to define the frames in a page. even though two of the frames are defined within a separate frameset.html NAME="contentFrame"> </FRAMESET> <FRAME SRC=navigate. All three frames have the same parent.10%"> <FRAMESET COLS="30%.

html NAME="navigateFrame"> </FRAMESET> The file muskel3.html) +--upperFrame------| | (muskel3.70%"> <FRAME SRC=category.html contains the skeleton for the upper frames and defines the following frameset: <FRAMESET COLS="30%. suppose you are using the frameset described in Example 2 in the previous section.frames[0] contentFrame is upperFrame.html) You can refer to the previous frames using the frames array as follows.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. If you want users to file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. (For information on the frames array. see the reference topic for the Frame object.html) | +--contentFrame (titles. listFrame and contentFrame share a parent: upperFrame.html NAME="contentFrame"> </FRAMESET> The following diagram shows the hierarchy of the frames.) q q q listFrame is top.frames[1] navigateFrame is top.html) | | +--contentFrame | (titles. Alternatively.frames[1] or top.htm (4 of 9) [30/08/2003 9:34:00 PM] .) q q q q upperFrame is top.frames[1] listFrame is upperFrame.html) | +-navigateFrame (navigate. you could create a window like the previous one but in which the top two frames have a parent separate from navigateFrame. as long as you specify the frame hierarchy.html NAME="upperFrame"> <FRAME SRC=navigate. For example. (For information on the frames array.frames[0] or top.html) | +---navigateFrame (navigate.frames[1] For an example of creating frames.frames[0] navigateFrame is top. see the reference topic for the Frame object. top | +--listFrame (category.10%"> <FRAME SRC=muskel3. Updating a frame You can update the contents of a frame by using the location property to set the URL.frames[0].frames[2] Example 2. The top-level frameset would be defined as follows: <FRAMESET ROWS="90%.frames[0] contentFrame is top.html NAME="listFrame"> <FRAME SRC=titles. see "Creating and updating frames: an example".frames[0].html) You can refer to the previous frames using the frames array as follows.htm not a frameset. top | | +--listFrame | | (category. defines a window. upperFrame and navigateFrame share a parent: the top window.

the file artists.html. contains a list of musicians sorted by category. TARGET="contentFrame">Toshiko Akiyoshi</A> TARGET="contentFrame">John Coltrane</A> TARGET="contentFrame">Miles Davis</A> TARGET="contentFrame">Dexter Gordon</A> TARGET="contentFrame">Betty Carter</A> TARGET="contentFrame">Ray Charles</A> The file alphabet.html. This file also defines a hypertext link users can click to display a description of each musician. in the frame navigateFrame.htm (5 of 9) [30/08/2003 9:34:00 PM] . contains an alphabetical list of musicians and the titles available for each.html (the categorical list) contains code similar to the following: <B>Music Club Artists</B> <P><B>Jazz</B> <LI><A HREF=titles. contains a list of musicians sorted alphabetically.html#0003 <LI><A HREF=titles. This file is displayed in listFrame when the user clicks the link for an alphabetical list.html#0001 <LI><A HREF=titles.location='artists.frames[0]. alphabet. An additional file. Creating and updating frames: an example If you designed the frameset in the previous section to present the available titles for a music club.. you could add the following button to navigateFrame: <INPUT TYPE="button" VALUE="Titles Only" onClick="top. in the frame listFrame..html is loaded into the frame upperFrame. Referring to and navigating among frames Because frames are a type of window.html'"> When a user clicks this button. contains hypertext links the user can click to choose how the musicians are displayed in listFrame: alphabetically or by category. you refer to frames and navigate among them as you do windows. the frames listFrame and contentFrame close and no longer exist. See "Referring to windows and frames" and "Navigating among windows and frames". navigate. The file category.htm be able to close the frame containing the alphabetical or categorical list of artists (in the frame listFrame) and view only the music titles sorted by musician (currently in the frame contentFrame). titles.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows.html (the alphabetical list) contains code similar to the following: <B>Music Club Artists</B> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. the frames and their HTML files could have the following content: q q q q category. in the frame contentFrame.html#0007 <LI><A HREF=titles.html#0010 <P><B>Soul</B> <LI><A HREF=titles.html#0004 .html.html#0006 <LI><A HREF=titles.html.

html#0002 HREF=titles. For details on the syntax for creating a frame. methods..html" TARGET="_parent"> <B>Musician Descriptions</B></A> The file titles.htm <LI><A <LI><A <LI><A <LI><A ..html#0004 TARGET="contentFrame">Toshiko Akiyoshi</A> TARGET="contentFrame">The Beatles</A> TARGET="contentFrame">Betty Carter</A> TARGET="contentFrame">Ray Charles</A> The file navigate. see the reference topic for the Frame object.html (the main file.html#0003 HREF=titles.html TARGET="listFrame"><B>By category</B></A> &nbsp&nbsp&nbsp <A HREF="artists. because the top window is the parent of navigateFrame.html TARGET="listFrame"><B>Alphabetical</B></A> &nbsp&nbsp&nbsp <A HREF=category. Referring to a window's properties.html is "_parent. the entire window is overwritten.html (the navigational links at the bottom of the screen) contains code similar to the following.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. Notice that the target for artists. Because the window object is the top-level object in the JavaScript client hierarchy." When the user clicks this link.html#0001 HREF=titles. HREF=titles. Referring to windows and frames The name you use to refer to a window depends on whether you are referring to a window's properties..htm (6 of 9) [30/08/2003 9:34:00 PM] . displayed in the frame on the right) contains code similar to the following: <!-----------------------------------------------------------------> <A NAME="0001"><H3>Toshiko Akiyoshi</H3></A> <P>Interlude <!-----------------------------------------------------------------> <A NAME="0002"><H3>The Beatles</H3></A> <P>Please Please Me <!-----------------------------------------------------------------> <A NAME="0003"><H3>Betty Carter</H3></A> <P>Ray Charles and Betty Carter . the window is essential for specifying the containership of objects in any window. <A HREF=alphabet. methods. and event handlers file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows.. and event handlers or to the window as the target of a form submit or a hypertext link.

frame2. when you open or close a window within an event handler.document.htm You can refer to the properties.document. Omit the window name: Because the existence of the current window is assumed. if (document. msgWindow. a call to close() without specifying an object name is equivalent to document. and you can use them optionally to refer to the current window. // Determine if a checkbox is checked if (checkboxWin.close().open() or window.checked=true // Determine if an option in a Select object is selected if (checkboxWin.document. methods. The statement changes the background color of frame2 to violet. top or parent: top and parent are also synonyms that you can use in place of the window name.musicForm. The statement displays an alert if a checkbox is checked. must be specified in the FRAMESET tag that creates the frameset. Example 1: refer to the current window. The name of a window variable: The window variable is the variable specified when a window is opened. For example.close() instead of simply using open() or close(). The following statement refers to a frame named frame2 that is in a window named window2.close() or self.musicForm.checkbox2. determine if the second option of a Select object is selected.selected) {alert('Option 1 is selected!')} // Select an option in a Select object checkboxWin.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. the current window remains active: checking the checkbox and selecting the selection option do not give focus to the window. you can close the current window by calling either window.document. For example. The statements determine if a checkbox is checked.checked) { alert('The checkbox on the musicForm in checkboxWin is checked!')} // Check the checkbox checkboxWin.musicForm.bgColor="teal" changes the background color of the frame named frame2 to teal. For example. and event handlers of the current window or another window (if the other window is named) using any of the following methods: q q q q self or window: self and window are synonyms for the current window. and select the second option of the Select object. you must specify window.checkbox1.musicForm.musicTypes. the statement parent.checked) { alert('The checkbox on the musicForm is checked!')} Example 2: refer to another window. frame2. see the reference topic for the window object. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. For example. close() closes the current window.selectedIndex=1 Example 3: refer to a frame in another window. The following statements refer to a form named musicForm in a window named checkboxWin. top refers to the topmost Navigator window. frame2 is a frame in the current frameset. check the checkbox.musicTypes. For more information on these methods of referring to windows.close(). However. Because of the scoping of static objects in JavaScript. The following statement refers to a form named musicForm in the current window.musicForm.options[1].document. and parent refers to a window containing a frameset.checkbox2. Even though object values are changed in checkboxWin.htm (7 of 9) [30/08/2003 9:34:00 PM] .close() closes a window called msgWindow. you do not have to reference the name of the window when you call its methods and assign its properties. The frame name.

The link displays the file named artists. If window2 does not exist.frame2.document. The link displays the anchor named abs_method in the file sesame.html#abs_method TARGET="contentFrame">abs</A> Example 4: literal frame name. then a link that loads the file doc2.html#numbers TARGET="window2">Numbers</A> Example 3: frame name.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows.htm window2. The window you specify is the window into which the link is loaded or. <A HREF=sesame. for a form. The link displays the anchor named numbers in the file doc2.html in the window window2.height=200')"> <P> <A HREF="doc2. and then a button that closes the window.html in the parent window of the current frameset. The following example creates a hypertext link to a second window.htm (8 of 9) [30/08/2003 9:34:00 PM] . The example has a button that opens an empty window named window2.bgColor="violet" Referring to a window in a form submit or hypertext link You use a window's name (not the window variable) when referring to a window as the target of a form submit or hypertext link (the TARGET attribute of a FORM or A tag).html" TARGET="_parent"> <B>Musician Descriptions</B></A> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. The following example creates a hypertext link to an anchor in a frame. <A HREF=doc2.width=200. This Link object appears in a frame within a frameset.'window2'.open(''.html is loaded into the parent window. <A HREF="artists. The following example creates a hypertext link to an anchor in a second window. The frame must be within the current frameset. Example 1: second window. 'resizable=no. The following example creates a hypertext link to a file. it is created. and the frame name must be defined in the NAME attribute of a FRAME tag.close()"> Example 2: anchor in a second window.html" TARGET="window2"> Load a file into window2</A> <P> <INPUT TYPE="button" VALUE="Close window2" onClick="msgWindow. <P> <INPUT TYPE="button" VALUE="Open window2" onClick="msgWindow=window. all frames in the frameset disappear and the content of artists. the window in which server responses are displayed. and when the user clicks the link.html in the frame named contentFrame.html into the newly opened window.

checkboxWin. The visual cue varies depending on which platform you are using. When a window has focus. For example.document. that does not make the second window active: the current window remains active.htm (9 of 9) [30/08/2003 9:34:00 PM] .html") .htm Navigating among windows and frames You navigate among frames the same way as you navigate among windows. <A HREF="doc2.. focus switches to window2. it is created. When the user clicks the link.. The following statement specifies window2 as the target of a hypertext link. Because the Text object is gaining focus. checkboxWin=window.open("doc2. You can give focus to a window programmatically by giving focus to an object in the window or by specifying the window as the target of a hypertext link. Example 1: give focus to an object in another window. it moves to the front and changes visually in some way. the window also gains focus and becomes active. The example also shows the statement that creates checkboxWin. Many Navigator windows can be open at the same time.html" TARGET="window2"> Load a file into window2</A> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. or give them focus. Although you can change an object's values in a second window.musicForm.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/windows. If window2 does not exist.city. the color of the window's title bar might change. The user can move among these windows by clicking them to make them active.focus() Example 2: give focus to another window using a hypertext link. The following statement gives focus to a Text object named city in a window named checkboxWin.

It assumes you are familiar with Java programming.htm LiveConnect iveConnect enables communication between JavaScript and Java applets in a page and between JavaScript and plug-ins loaded on a page. Use Java code to access JavaScript methods and properties.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. see "Applet" and "Plugin". q q q Use JavaScript to access Java variables.lang. To confirm they are enabled.htm (1 of 12) [30/08/2003 9:34:01 PM] . the message appears in the Console. if you do this. q q Make sure Enable Java is checked. or to trace the values of variables at different places in a program's execution. For the HTML syntax required to add applets and plug-ins to your web page. To display the Java Console. uncheck the checkboxes. Enabling LiveConnect LiveConnect is enabled by default in Navigator 3. You can use the Java Console to present messages to users. LiveConnect will not work. see Chapter 12. When you use the class variables out or err in java. choose Network Preferences from the Options menu. Control Java applets or plug-ins with JavaScript. then choose the Languages tab." This chapter explains how to use LiveConnect in Netscape Navigator. For the Netscape packages reference.System to output a message. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. and packages directly. classes. Make sure Enable JavaScript is checked. methods.0. The Java Console The Java Console is a Navigator window that displays Java messages. both Java and JavaScript must be enabled. choose Show Java Console from the Options menu. "The Netscape packages. To disable either Java or JavaScript. For LiveConnect to work.

net.0 contains a java_30 file that includes the following Java packages: q q netscape packages to enable JavaScript and Java communication. These packages are not documented because they are implemented in the same way as the original Sun packages.javascript implements the JSObject class to allow your Java applet to access JavaScript methods and properties. "The Netscape packages. These packages have been tested by Sun. and similar security enhancements will be implemented in future releases of the Sun JDK.2 Java Development Kit (JDK) classes. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon.applet is a replacement for the Sun JDK package sun. To display the Java Console.println("Hello. the user chooses Show Java Console from the Options menu. The new java and sun packages replace packages in the Sun 1." In addition.out. netscape. Note that most users probably do not display the Java Console. The file java_30 contains the following netscape packages: q q netscape.htm For example.zip. About the Netscape packages Navigator 3.htm (2 of 12) [30/08/2003 9:34:01 PM] . java and sun packages to provide security enhancements for LiveConnect. java_30 contains some other netscape packages: q q netscape.applet. netscape. world!" in the Java Console: public void init() { System. world!") } You can use the Java Console to present messages to users. or to trace the values of variables at different places in a program's execution.net is a replacement for the Sun JDK package sun.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon.0.plugin implements the Plugin class to enable JavaScript and Java plug-in communication. It also implements JSException to throw an exception when JavaScript code returns an error. Use these packages until the Sun JDK provides these security enhancements. Compile your Java plug-in with this class to allow applets and JavaScript code to manipulate the plug-in. the following Java code displays the message "Hello. These packages are documented in Chapter 12.

zip. Control Java applets. with the name of the Packages object optionally prepended: [Packages. For example.className.lang. Accessing Java directly When LiveConnect is enabled. Use Java syntax to reference Java objects in JavaScript. and netscape are aliases for Packages.System file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon.]packageName. For example. For example.sun. place the file in the classpath of the JDK compiler in either of the following ways: q q Create a CLASSPATH environment variable to specify the paths and names of java_30 and classes. in code.out. sun.lang. Java packages and classes are properties of the Packages object. and netscape packages. Specify the location of java_30 when you compile by using the -classpath command line parameter. JavaScript can make direct calls to Java methods. In JavaScript. Control Java plug-ins.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. You can specify an environment variable in Windows NT by double-clicking the System icon in the Control Panel and creating a user environment variable called CLASSPATH with a value similar to the following: D:\JDK\java\lib\classes. JavaScript to Java communication LiveConnect provides three ways for JavaScript to communicate with Java: q q q Call Java methods directly. Packages.netscape.System as either Packages. the java_30 file is delivered in the Program\Java\classes directory beneath the Navigator directory.zip.System or as java.htm (3 of 12) [30/08/2003 9:34:01 PM] .java.lang.println to display a message on the Java Console. you can refer to the Java class java. java.D:\Navigator\Program\java\classes\java_30 See the Sun JDK documentation for more information about CLASSPATH. you can call System.java. sun.methodName The name Packages is optional for java. on Windows. and Packages.htm Using the Netscape packages To access the packages in java_30.

lang. the JavaScript string is automatically converted to a java. For example. Because println expects a java.drawString("Hello world!". and properties of an applet are available for JavaScript access.Graphics.Applet.err. For example. For example.String argument. All public variables. } } The following HTML runs and displays the applet.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. Referencing applets Each applet in a document is reflected in JavaScript by document. You can even use Java class constructors in JavaScript. 25).out.lang.System. 50. you can use buttons on an HTML form to start and stop a Java applet that appears elsewhere in the document. the following JavaScript code prints a message to the Java Console: var System = java.htm in your code.applet. you can reference elements of the array through the applet name (as in an associative array) or by the ordinal number of the applet on the page (starting from zero). import java.lang.lang. consider the basic "Hello World" applet in Java: import java.println(myDate) Controlling Java applets You can use JavaScript to control the behavior of a Java applet without knowing much about the internal construction of the applet. the following JavaScript code creates a Java Date object and prints it to the Java Console. methods. The name Packages is required for other packages.appletName. and names it "HelloWorld" (with the NAME attribute): file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon.Date() System.awt. where appletName is the value of the NAME attribute of the <APPLET> tag. Access fields and methods in a class with the same syntax that you use in Java. public class HelloWorld extends Applet { public void paint(Graphics g) { g.htm (4 of 12) [30/08/2003 9:34:01 PM] .println("Greetings from JavaScript") The first line in this example makes the JavaScript variable System refer to the class java.util.String. For example. The applets array also contains all the applets in a page. The second line invokes the println method of the static variable err in the Java System class. var mydate = new java.System System.

Define a setString method that accepts a string argument. The Java source code then looks as follows: import java. You can get and set property values. and you can call methods that return string. } public void setString(String aString) { myString = aString. public void init() { myString = new String("Hello. world!").Applet.Component).htm <APPLET CODE="HelloWorld. and its ancestor classes and packages are available in JavaScript.class" NAME="HelloWorld" WIDTH=150 HEIGHT=25> </APPLET> You can reference this applet in JavaScript in either of the following ways: document. modify the HelloWorld applet shown above.applets[0] The applets array has a length property.applets. import java. 20). } file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. } public void paint(Graphics g) { g. and make the following changes: q q Override its init method so that it declares and initializes a string called myString.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. All public variables declared in an applet. that indicates the number of applets in the document.applet.drawString(myString. public class HelloWorld extends Applet { String myString.applets["HelloWorld"] If this is the first applet in the document (topmost on the page). assigns it to myString.length. and boolean values.awt. you could also reference it as: document. Example 1: Hello World So for example.awt. 25.HelloWorld document.Graphics. and calls the repaint method. numeric.htm (5 of 12) [30/08/2003 9:34:01 PM] . repaint(). Static methods and properties declared in an applet are available to JavaScript as methods and properties of the Applet object. (The paint and repaint methods are inherited from java. document.

str.htm (6 of 12) [30/08/2003 9:34:01 PM] .class" WIDTH=500 HEIGHT=60 NAME="colorApp"> </APPLET> <FORM NAME=colorText> <P>Enter new text for the flashing display: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon.HelloWorld. Make the onClick event handler for the button call the setString method of HelloWorld with the string from the text field as its argument. and another pushbutton changes the flashing text that it displays. Two buttons start and stop this applet. consider an applet that displays text that flashes in different colors.form1. and load the HTML page into Navigator.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon.value)"> <BR> <INPUT TYPE="text" SIZE="20" NAME="str"> </FORM> When you compile the HelloWorld applet.htm } Making the message string a variable allows you to modify it from JavaScript. World!" displayed in the gray applet panel. Example 2: Flashing color text applet As another slightly more complex example. Enter new text for the flashing display: Click the button to change the display: Change Text The HTML source for this example is as follows: <APPLET CODE="colors. you initially see "Hello. This demonstrates controlling an applet from JavaScript.class" NAME="Hello" WIDTH=150 HEIGHT=25> </APPLET> <FORM NAME="form1"> <INPUT TYPE="button" VALUE="Set String" onClick="document.setString(document. The HTML file now looks like this: <APPLET CODE="HelloWorld1. Now modify the HTML file as follows: q q Add a form with a button and a text field. However. you can now change it by entering text in the text field and clicking on the button.

colorText.value)"> </FORM> This applet uses the public method setString to specify the text for the flashing string that appears. the onClick event handler of the button lets a user change the "Hello.avi NAME="myEmbed" WIDTH=320 HEIGHT=200> If this HTML defines the first plug-in in a document. The Plug-in Developer's Guide contains information on: q q Calling Java methods from plug-ins Calling a plug-in's native methods from Java file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon.Plugin.colorApp. For example. you can access its static variables and methods the way you access an applet's variables and methods. that indicates the number of plug-ins embedded in the document.colorText. The event handler passes the value that a user enters in the text field to the setString method in the Java applet. The embeds array has a length property.myEmbed If the plug-in is associated with the Java class netscape. Controlling Java plug-ins Each plug-in in a document is reflected in JavaScript as an element in the embeds array.length.setString(document. See "Determining installed plug-ins" for more information about plug-ins.textBox.setString(document. world!" string that the applet initially displays by calling the setString method as follows: <INPUT TYPE="button" VALUE="Change Text" onClick="document. document. In the HTML form.embeds["myEmbed"] document. colorText is the name of the HTML form and textBox is the name of the text field. you can access it in any of the following ways: document.plugin.embeds[0] document. the following HTML code includes an AVI plug-in in a document: <EMBED SRC=myavi.embeds.htm <INPUT TYPE="text" NAME="textBox" LENGTH=50> <P>Click the button to change the display: <INPUT TYPE="button" VALUE="Change Text" onClick="document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon.value)"> In this code.htm (7 of 12) [30/08/2003 9:34:01 PM] .textBox.colorApp.

javascript. if win is a previously-declared variable of type JSObject.getMember("name"). This means that all JavaScript values appear in Java as objects of class java. Other objects are wrapped with a JSObject. For example. Float. Objects that are wrappers around Java objects are unwrapped. you must get a handle for the Navigator window. (JSObject) window..getMember("document"). numbers and booleans are converted to Java String. passing it the Applet object. Getting a handle for the JavaScript window Before you can access JavaScript. import the Netscape javascript package: import netscape. The author of an HTML page must permit an applet to access JavaScript by specifying the MAYSCRIPT attribute of the <APPLET> tag. Java to JavaScript communication To access JavaScript methods.lang. properties. Attempting to access JavaScript from an applet that does not have the MAYSCRIPT attribute generates an exception.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon.JSObject to get a window handle.javascript. you generally will have to cast them to the appropriate subclass of Object. for example: (String) window.htm Data type conversion Values passed from JavaScript to Java are converted as follows: q q q Strings.* The package netscape. Use the getWindow method in the class netscape. the following Java code assigns a window handle to win: public class myApplet extends Applet { public void init() { file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. The MAYSCRIPT tag is needed only for Java to access JavaScript.htm (8 of 12) [30/08/2003 9:34:01 PM] . and data structures from your Java applet. This prevents an applet from accessing JavaScript on a page without the knowledge of the page author. To use them.javascript defines the JSObject class and the JSException exception object.Object. and Boolean objects respectively. it is not needed for JavaScript to access Java.

Use getWindow to get a handle for the JavaScript window. myForm=win. then use eval to access a JavaScript method. the following Java code allows you to access its checked property: public void init() { win = JSObject.getMember("jazz").testForm through the variable myForm: public void init() { win = JSObject. JSObject doc = (JSObject) win.htm (9 of 12) [30/08/2003 9:34:01 PM] .getMember("checked"). } Calling JavaScript methods The eval method in the class netscape. For example. JSObject myForm = (JSObject) doc.JSObject in Java. Use the following syntax to call JavaScript methods: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. the following Java code allows you to access the JavaScript object document.testForm") } Note that you could use the following lines in place of myForm=win.getMember("testForm").javascript.javascript. Values passed between Java and JavaScript are converted as described in "netscape.jazz is a checkbox. } } Accessing JavaScript objects and properties The getMember method in the class netscape.getMember("testForm").JSObject let you evaluate an arbitrary JavaScript expression.testForm"): JSObject doc = (JSObject) win.getMember("document").getWindow(this).eval("document. If the JavaScript object document.htm JSObject win = JSObject.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon.JSObject lets you access JavaScript objects and properties. Notice that JavaScript objects appear as instances of the class netscape.JSObject".javascript.javascript. then call getMember to access each JavaScript object in a containership path in turn.getWindow(this).getMember("document"). JSObject check = (JSObject) myForm. Call getWindow to get a handle for the JavaScript window.testForm.getWindow(this). Boolean isChecked = (Boolean) check. JSObject myForm = (JSObject) doc.eval("document.

call(methodName.drawString(myString. int x. Float. If you want to pass primitive values to a JavaScript method. the following Java code uses eval to call the JavaScript alert method when a mouseUp event occurs: public void init() { JSObject win = JSObject.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. For example. you must use the Java object wrappers (such as Integer. 25. win. Each time the applet is painted (when it is initalized.getWindow().eval("expression") expression is a JavaScript expression that evaluates to a JavaScript method call.getWindow(this). args). int y) { win. recompile the applet. and when the page is reloaded) a JavaScript alert box is displayed. 20).eval("alert(\"Hello world!\"). } Then add the MAYSCRIPT attribute to the <APPLET> tag in the HTML page.htm JSObject. This is a simple illustration of calling JavaScript from Java. } Another way to call JavaScript methods is with the call method of JSObject. and then populate an Array with such objects. String args[] = {"Painting!"}. argArray) where argArray is an Array of Java objects used to pass arguments to the JavaScript method. JSObject win = JSObject. } public boolean mouseUp(Event e. This same effect could be achieved with the following: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. when you enter a new text value.call("alert"."). Example: Hello World Returning to the HelloWorld example. modify the paint method in the Java code so that it calls the JavaScript alert method (with the message "Painting!") as follows: public void paint(Graphics g) { g. and Boolean). and try it.getWindow(this).htm (10 of 12) [30/08/2003 9:34:01 PM] . Use the following to call a JavaScript method from Java when you want to pass Java objects as arguments: JSObject. return true.

This is a simple illustration of calling a user-defined function from Java.htm public void paint(Graphics g) { g.appName + " " + navigator.drawString(myString. short. Then modify the init method in your Java code similarly to the way you modified paint: public void init() { myString = new String("Hello. When you recompile the applet and reload the HTML page (and re-initialize the applet).getWindow(this). char. add the following function to the <HEAD> of the HTML page with the HelloWorld applet: <SCRIPT> function test() { alert("You are using " + navigator. int. 20). a JavaScript alert dialog box will display the version of Navigator you are running. Data type conversion Values passed from Java to JavaScript are converted as follows: q Java byte. to ensure that the applet is re-initialized. JSObject win = JSObject. float. } Note You may have to reload the HTML page by choosing Open File from the File menu instead of clicking the Reload button.getWindow(this) String args2[] = {""} win. even though the method does not take any arguments.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. long.appVersion) } </SCRIPT> This simple function displays an alert dialog box containing the name and version of the client software being used.eval("alert(`Painting')"). file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. 25. For example.call("test". world!") JSObject win = JSObject. args2) } Notice that args2 is declared as an array with no elements. Calling user-defined functions You can also call user-defined functions from a Java applet.htm (11 of 12) [30/08/2003 9:34:01 PM] . and double are converted to JavaScript numbers. win.

length.htm q q q q A Java boolean is converted to a JavaScript boolean. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. and determine its length with arrayName. converting to a number will call the floatValue method if possible and fail otherwise. Converting this wrapper to a string will call the toString method on the original object. Java arrays are converted to a JavaScript pseudo-Array object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/livecon. which can be used to access methods and fields of the Java object. An object of any other class is converted to a JavaScript wrapper.htm (12 of 12) [30/08/2003 9:34:01 PM] . Converting to a boolean will attempt to call the booleanValue method in the same way. An object of class JSObject is converted to the original JavaScript object. this object behaves just like a JavaScript Array object: you can access it with the syntax arrayName[index] (where index is an integer).

0. Category New objects Feature Applet Area Array Boolean FileUpload Description Includes a Java applet in a web page Defines image maps Lets you create arrays and work with them Lets you work with Boolean values A file upload element on an HTML form. properties. methods.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc. Note Language features added in Navigator 3. and other features added in JavaScript for Navigator 3.0. event handlers.htm (1 of 10) [30/08/2003 9:34:02 PM] .htm Features added after version 1 he following lists summarize the additions and changes to JavaScript since Navigator 2. The lists show new functionality and changed functionality.0 are not incorporated in LiveWire 1. New functionality The following table lists objects.0. a file upload element lets the user supply a file as input Specifies a string of JavaScript code to be compiled as a function An image on an HTML form Function Image file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc.

in pixels.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc.htm (2 of 10) [30/08/2003 9:34:02 PM] . A string specifying the width.htm MimeType A MIME type (Multipart Internet Mail Extension) supported by the client Lets you work with numeric values A Select object option created using the Option() constructor A plug-in module installed on the client You can remove an object by setting its object reference to null. of an image border Specifies whether a window is closed A boolean value that indicates whether Navigator has completed its attempt to load an image Specifies the function that creates an object prototype A string specifying the complete URL of the current history entry A description of a MIME type or plug-in Specifies the domain name of the server that served a document The Plugin object for the plug-in that is configured for the specified MIME type Number Option Plugin Object deletion New properties border closed complete constructor current description domain enabledPlugin file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc. See "Object deletion".

htm (3 of 10) [30/08/2003 9:34:02 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc. This value is represented as "Infinity" lowsrc MAX_VALUE MIN_VALUE NaN NEGATIVE_INFINITY next opener POSITIVE_INFINITY file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc.htm filename height hspace The name of a plug-in file on disk A string specifying the height of an image in pixels A string specifying a margin in pixels between the left and right edges of an image and the surrounding text A string specifying the URL of a low-resolution version of an image to be displayed in a document The maximum numeric value representable in JavaScript The smallest positive numeric value representable in JavaScript A special value representing Not-ANumber. this value is represented as "-Infinity" A string specifying the complete URL of the next history entry Specifies the window of the calling document when a window is opened using the open method A special numeric value representing infinity. This value is represented as NaN A special numeric value representing negative infinity.

htm previous A string specifying the complete URL of the previous history entry Defines a property that is shared by all objects of the specified type A string specifying the URL of an image to be displayed in a document A string listing possible file suffixes (also known as file name extensions) for the MIME type Specifies the type of form element or the name of a MIME type A string specifying a margin in pixels between the top and bottom edges of an image and the surrounding text A string specifying the width of an image in pixels Reflects all the <APPLET> tags in a document in source order Reflects all the <EMBED> tags in a document in source order Reflects all the history entries in a window in source order Reflects all the <IMG> tags in a document in source order (images created with the Image() constructor are not included in the images array) prototype src suffixes type vspace width New arrays applets embeds array history array images file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc.htm (4 of 10) [30/08/2003 9:34:02 PM] .

htm mimeTypes Reflects all the MIME types supported by the client (either internally. or by plug-ins) Reflects all the plug-ins installed on the client in source order Specifies whether Java is enabled Joins all elements of an array into a string Makes newly installed plugins available. via helper applications.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc.htm (5 of 10) [30/08/2003 9:34:02 PM] . updates related arrays such as the plugins array. and optionally reloads open documents that contain plugins Forces a reload of the window's current document Loads the specified URL over the current history entry Simulates a mouse click on a reset button Transposes the elements of an array: the first array element becomes the last and the last becomes the first Scrolls a window to a specified coordinate Sorts the elements of an array Splits a String object into an array of strings by separating the string into substrings plugins New methods javaEnabled join refresh reload replace reset method reverse scroll sort split file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc.

you can reset an event handler specified by HTML from within JavaScript. See "Using JavaScript expressions as HTML attribute values". onError onMouseOut onReset Resetting event handlers from within JavaScript New operators typeof void New HTML tags and attributes JavaScript entities file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc. Returns the data type of its operand Specifies an expression to be evaluated without returning a value JavaScript entities for HTML attribute values.0.htm taintEnabled valueOf New functions taint untaint New event handlers onAbort Specifies whether data tainting is enabled Returns the primitive value of an object Adds tainting to a data element or script Removes tainting from a data element or script Executes JavaScript code the user aborts the loading of an image Executes JavaScript code when the loading of a document or image causes an error Executes JavaScript code when the mouse pointer leaves an area (client-side image map) or link Executes JavaScript code when a reset event occurs In JavaScript for Navigator 3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc. See "Calling event handlers explicitly".htm (6 of 10) [30/08/2003 9:34:02 PM] .

See "Determining installed plug-ins". See "Specifying a file of JavaScript code"." You can use JavaScript to determine whether a user has installed a particular plug-in. LiveConnect enables communication between JavaScript and Java applets in a page and between JavaScript and plug-ins loaded on a page. See "Specifying the JavaScript version". "LiveConnect.htm (7 of 10) [30/08/2003 9:34:02 PM] . You can also determine whether a client is capable of handling a particular MIME (Multipart Internet Mail Extension) type. See Chapter 4. Displays alternate content for old browsers or when the user has disabled JavaScript in Navigator. LANGUAGE attribute of <SCRIPT> the tag <NOSCRIPT> tag Java-JavaScript communication LiveConnect Plug-in detection Determining installed plug-ins file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc.htm SRC attribute of <SCRIPT> the tag Allows you to use JavaScript code in an external file. See "Specifying alternate content with the NOSCRIPT tag".file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc. Allows you to specify the JavaScript version.

See "Using data tainting for security".htm Security Data tainting Navigator prevents scripts from fetching private information such as directory structures or user session history. Category Objects Feature Form object Frame history object Link object location navigator Object prototypes (see prototype) Select object Description Added reset method. added javaEnabled method Added ability to create properties to be shared by all objects of the same type Programmatically modifiable Select objects and the ability to add options and delete options file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc. onError.htm (8 of 10) [30/08/2003 9:34:02 PM] .0. and previous properties Added onMouseOut event handler Added reload and replace methods.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc. added onBlur. and onFocus event handlers Added current. Changed functionality The following table lists changes to functionality that existed in JavaScript for Navigator 2. and scroll methods. Data tainting retains the security restriction but provides a means of secure access to specific components on a page. added onReset event handler Added blur. next. focus. changed the way documents are loaded when location is set Added mimeTypes and plugins arrays.

Button. you had to add an empty string to another window's string to reference it) Added closed and opener properties. Button. FileUpload. Now works for window. added onBlur. frame. onError.htm (9 of 10) [30/08/2003 9:34:02 PM] . and onFocus event handlers If you initially define a property by its name. Radio. added split method. and Submit objects window object Indexing object properties Properties Indexing arrays with strings blur close (window object) eval Methods focus open (document object) Added "replace" parameter. it evaluates a string of JavaScript code in the context of the specified object Now works for window. added ability to pass strings among scripts in different windows or frames (in previous releases. Reset. you must always refer to it by its name. See "Indexing object properties".open() or document. Radio.open("text/html") now clears the current document if it has finished loading random toString write writeln Functions isNaN Now works on all platforms Added radix parameter. and "Array". document. Reset. worked only on Unix platforms) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc. Checkbox.htm String Added String() constructor (in previous releases. added prototype property. you must always refer to it by its index. added blur. which specifies the base to use for representing numeric values Users can print and save generated HTML using the commands on the File menu Users can print and save generated HTML using the commands on the File menu Now works on all platforms (in previous releases. "Array object". and Submit objects Has new security enhancements Now a method of every object (was previously a built-in function). you construct strings by quoting characters). Added ability to index arrays using strings (as in an associative array). and scroll methods. See "Navigator's object arrays". and if you initially define a property by an index. Checkbox. FileUpload.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc. focus. which causes the new document to reuse the history entry that the previous document used. frame.

in previous releases. Button. Checkbox. in previous releases. Button. FileUpload.htm (10 of 10) [30/08/2003 9:34:02 PM] . Radio. it returned NaN on Solaris and Irix and zero on all other platforms Now applies to window. frame. frame. Checkbox. and Submit objects Added the ability to return false to cancel the action associated with a click event Now applies to window. Radio. Reset. FileUpload. and Submit objects parseInt Event handlers onBlur onClick onFocus file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/newfunc. it returned NaN on Solaris and Irix and zero on all other platforms Now returns NaN on all platforms if the first character of the specified string cannot be converted to a number.htm parseFloat Now returns NaN on all platforms if the first character of the specified string cannot be converted to a number. Reset.

use a JavaScript URL in a standard HTML hyperlink: <A HREF="javascript:countJumps()">Page 1</A> This example assumes page1 is a string representing a URL. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic.location=page1 } To call the function. You can use JavaScript URLs in many ways to add functionality to your applications. you can put any statements or function calls after the "javascript:" URL prefix. For example. you could increment a counter p1 in a parent frame whenever a user clicks a link. You simply use a string beginning with "javascript:" as the value for the HREF attribute of anchor tags. If the expression evaluates to a defined type. The chapter covers the following topics: q Using JavaScript URLs Using client-side image maps Using server-side image maps Using the status bar q Using cookies Using data tainting for security Determining installed plug-ins q q q q q Using JavaScript URLs You should be familiar with the standard types of URLS: http.htm (1 of 10) [30/08/2003 9:34:03 PM] . file. With Navigator you can also use URLs of type "javascript:" to execute JavaScript statements instead of loading a document.htm Advanced topics his chapter describes some special concepts and applications that extend the power and flexibility of Navigator JavaScript. If the value of the expression following a "javascript:" URL prefix evaluates to undefined. no new document is loaded. you can define a hyperlink as follows: <A HREF="javascript:history.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic. ftp.go(0)">Reload Now</A> to reload the current page when the user clicks it. the value is converted to a string that specifies the source of the document to load. and so on. For example. using the following function: function countJumps() { parent. In general.p1++ window.

or polygons. but standard (sometimes called server-side) image maps provide even more flexibility.46" HREF="contents.16. Traditionally.y where URL is the document specified by the value of the HREF attribute.search if (str == "") document.html" target="javascript:alert(`Loading Contents.14" HREF ="javascript:top.'). For example. With Navigator JavaScript. you can also use JavaScript URLs in client-side image maps.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic.write("<P>No coordinates specified.85.location = newnav. Instead of standard URLs. The "about:logo" image is built in to Navigator and displays the Netscape logo. however.0.close(). You specify a standard image map with the ISMAP attribute of an IMG tag that is a hyperlink.html"> <AREA SHAPE="RECT" COORDS="0. circles. you can perform the lookup on the client. suppose you have a file named img.html with the following content: <H1>Click on the image</H1> <P> <A HREF="img. For example. Navigator requests a URL of the form URL?x. and x and y are the horizontal and vertical coordinates of the mouse pointer (in pixels from the top-left of the image) when you clicked.") // the location of the comma file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic.htm (2 of 10) [30/08/2003 9:34:03 PM] . <MAP NAME="buttonbar"> <AREA SHAPE="RECT" COORDS="0. for example.html"><IMG SRC="about:logo" BORDER=0 ISMAP></A> <SCRIPT> str = location.html"> </MAP> Using server-side image maps Client-side image maps provide functionality to perform most tasks. image-map requests are sent to servers. the areas can be rectangles. window. and a CGI program performs a database lookup function.html"><IMG SRC="about:logo" BORDER=0 ISMAP></A> When you click an image with the ISMAP attribute. You can use the search property of the location object to parse the x and y coordinates and perform an action accordingly. You can define areas within the image that are hyperlinks to distinct URLs.htm Using client-side image maps A client-side image map is defined with the MAP tag.location = contents. <A HREF="img.indexOf(".0. top.") else { commaloc = str.

The statements in the else clause then display the x and y coordinates.length)) } </SCRIPT> When you click a part of the image. The event handler must return true to set status. For example. defaultStatus = "Some rise.substring(commaloc+1. str. to display messages in the Navigator status bar at the bottom of the window. Navigator reloads the page (because the HREF attribute specifies the same document). Navigator normally uses the status bar to display such messages as "Contacting Host.return true"> Contents</A> This example displays the hint "Click to display contents" in the status bar when you move the mouse pointer over the link. some fall. cookies provide a way to maintain information between client requests.write("<P>The x value is " + str. status and defaultStatus. simply set defaultStatus." and "Document: Done.". This section discusses basic uses of cookies and illustrates with a simple example. For example. some climb. Netscape cookies are a mechanism for storing persistent data on the client in a file called cookies.txt. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic. adding the x and y coordinates of the mouse-click to the URL. commaloc)) document.to get to Terrapin" Creating hints with onMouseOver and onMouseOut By default. see Appendix D." The defaultStatus message appears when nothing else is in the status bar. For example. to display a custom message after the document has finished loading. "Netscape cookies. Because HyperText Transport Protocol (HTTP) is a stateless protocol. The status property displays a transient message in the status bar.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic.htm (3 of 10) [30/08/2003 9:34:03 PM] .substring(1.status='Click to display contents'.html" onMouseOver="window. You can set status in the onMouseOut and onMouseOver event handlers of a hyperlink or image area to display hints in the status bar instead. <A HREF="contents.htm document. you could redirect to another page (by setting location) or perform some other action based on the values of x and y.write("<P>The y value is " + str... when you move the mouse pointer over a hyperlink. Using cookies For a complete description of cookies.. In practice. You can set these properties to display custom messages. such as when the user moves the mouse pointer over a link.. the status bar displays the destination URL of the link. Using the status bar You can use two window properties.

or blank (space) characters. expDate is the expiration date. DD-Mon-YY HH:MM:SS GMT Although it's slightly different from this format. comma. see Appendix D. Here are some basic things you can do with cookies: q q Set a cookie value. If expDate is not specified. you may need to use an additional path parameter for each cookie.cookie property is a string that contains all the names and values of Navigator cookies. For more information. Expiration date is optional file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic. The expiration date is an optional parameter indicating how long to maintain the cookie.expires=expDate. Cookies can be associated with one or more directories.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic. For more information on escape and unescape. you must use the escape function to encode them and the unescape function to decode them. If your files are all in one directory. then you need not worry about this. It is convenient to define functions to perform these tasks. name is the name of the datum being stored.htm (4 of 10) [30/08/2003 9:34:03 PM] . If your files are in multiple directories. "Netscape cookies. You can use this property to work with cookies in JavaScript. Twenty cookies per server or domain (completely specified hosts and domains are treated as separate entities and have a twenty-cookie limitation for each. see the topics in the reference section. not combined). If name and value contain any semicolon. Get a cookie value. for example. 4 Kbytes per cookie. is a function that sets cookie values and expiration: // Sets cookie values. the cookie expires when the user exits the current Navigator session. given the cookie name. Limitations Cookies have these limitations q q q Three hundred total cookies in the cookie file. for the sum of both the cookie's name and value. the date string returned by the Date method toGMTString can be used to set cookie expiration dates. optionally specifying an expiration date.htm Each cookie is a small item of information with an optional expiration date and is added to the cookie file in the following format: name=value. Here. and value is its value. Navigator maintains and retrieves a cookie only if its expiration date has not yet passed." Using cookies with JavaScript The document. in GMT date format: Wdy.

expire) { document.htm (5 of 10) [30/08/2003 9:34:03 PM] . register.cookie. they will see a personal greeting. Then there is a form that calls register to add a cookie. This function.setTime(today.cookie. If they return to your page within a year. creates a cookie with the name TheCoolJavaScriptPage and the value passed to it as an argument. name.length > 0) { // if there are any cookies offset = document. expires) } The BODY of the document uses getCookie (defined in the previous section) to check whether the cookie for TheCoolJavaScriptPage exists and displays a greeting if it does. you can create a simple page users can fill in to "register" when they visit your page.cookie. value.length // set index of beginning of value end = document. offset) // set index of end of cookie value if (end == -1) end = document. given the name of the cookie: function getCookie(Name) { var search = Name + "=" if (document.".go(0) to redraw the page. You need to define one additional function in the HEAD of the document.indexOf(". end)) } } } Notice the use of unescape to decode special characters in the cookie value. commas.length return unescape(document. spaces) in the value string.getTime() + 60*60*24*365) setCookie("TheCoolJavaScriptPage". function register(name) { var today = new Date() var expires = new Date() expires. The onClick event handler also calls history. The following function returns a cookie value.cookie.substring(offset. Using cookies: an example Using the cookie functions defined in the previous section.toGMTString())) } Notice the use of escape to encode special characters (semicolons. <BODY> <H1>Register Your Name with the Cookie-Meister</H1> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic. This function assumes that cookie names do not have any special characters. expires=" + expire.cookie = name + "=" + escape(value) + ((expire == null) ? "" : (".indexOf(search) if (offset != -1) { // if cookie exists offset += search.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic.cookie.htm // function setCookie(name.

q q When data tainting is enabled. The following properties are tainted by default: Object document Form history Tainted properties cookie. links. ". <BR> <FORM onSubmit="return false"> Enter your name: <INPUT TYPE="text" NAME="username" SIZE= 10><BR> <INPUT TYPE="button" value="Register" onClick="register(this. domain.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic. no matter what server the other window's document was loaded from. URL action current.username. and JavaScript cannot pass these tainted values on to any server without the user's permission.") </SCRIPT> <P> Enter your name.. When data tainting is disabled. How tainting works A page's author is in charge of tainting elements. yourname) else document.write("<P>You haven't been here in the last year. history. referrer. you will be greeted with a personalized greeting. lastModified. defaultChecked.go(0)"> </FORM> Using data tainting for security Navigator version 2. the author of the other window taints (marks) property values or other data that should be secure or private. When you return to this page within a year. forms.form.0 has a feature called data tainting that retains the security restriction but provides a means of secure access to specific components on a page. toString any form input element checked.write("<P>Welcome Back. as described in "Enabling tainting". a script cannot access any properties of a window on another server. next. name. the end user sets an environment variable.. title. This restriction prevents scripts from fetching private information such as directory structures or user session history. previous. value file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic.htm <P> <SCRIPT> var yourname = getCookie("TheCoolJavaScriptPage") if (yourname != null) document. However. To enable tainting.htm (6 of 10) [30/08/2003 9:34:03 PM] . selectedIndex. JavaScript in one window can see properties of another window.value). JavaScript for Navigator 3. defaultValue. toString.02 and later automatically prevents scripts on one server from accessing properties of documents on a different server.

These functions each take a single data element as an argument. pathname. functions. value hash. If the end user does not enable tainting and a script attempts to access properties of a window on another server. href. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic. host. If a string is tainted. edit the resource with type "Envi" and number 128 in the Netscape application by removing the two ascii slashes "//" before the NS_ENABLE_TAINT text at the end of the resource. hostname. You can taint and untaint properties. objects) in your scripts to prevent the returned values from being used inappropriately by other scripts or propagating beyond another script. the script itself accumulates taint. You might want to remove tainting from a data element so other scripts can read and do anything with it. the end user sets the NS_ENABLE_TAINT environment variable as follows: q q q On Unix. selected.bat or NT user settings. and objects. variables.htm (7 of 10) [30/08/2003 9:34:03 PM] . You cannot untaint another server's data elements. port. On Macintosh. use set in autoexec. text. a message is displayed indicating that access is not allowed.htm Select option location and Link window defaultSelected. variables. functions. "1" will do. and untaint removes tainting from a data element. protocol. otherwise it executes function2. Enabling tainting To enable data tainting. To determine whether tainting is enabled.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic. NS_ENABLE_TAINT can have any value. for. any substring of the string is also tainted. if (navigator. as described in "Tainting and untainting individual data elements". a dialog box is displayed so the user can confirm or cancel the operation. Tainting and untainting individual data elements You can taint data elements (properties.taintEnabled()) { function1() } else function2() For details on taintEnabled. The following code executes function1 if data tainting is enabled. search. status You can use tainted data elements any way you want in your script. but if your script attempts to pass a tainted element's value or any data derived from it over the network in any way (for example. If a script examines a tainted value in an if. or while statement. You control the tainting of data elements with two functions: taint adds tainting to a data element. use the taintEnabled method. Values derived from tainted data elements are also tainted. On Windows. see "taintEnabled". via a form submission or URL). toString defaultStatus. You cannot untaint another server's properties or data elements. use the setenv command in csh. If a tainted value is passed to a function. the return value of the function is tainted.

Calling untaint with no arguments removes taint from the accumulator only if the accumulator holds taint from the current window only. if it holds taint from operations done on data elements from other servers. or copy of the primitive type value (number or boolean value). Otherwise.write into generated tags. server. Tainting that results from conditional statements In some cases. and the taint code of the data being sent are compatible will the operation proceed. It propagates through document. The accumulator mixes different taint codes to create new codes that identify the combination of data origins (for example.org/cgi. JavaScript assigns a unique taint code to each server's data elements. serverA. taint accumulates until the document is unloaded.write("<img src=http://evil. both functions return a marked or unmarked reference to the argument object. untaint will have no effect.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic. the taint code of the targeted server. or at least one is identity (null). Compatible means that either two taint codes are equal. and while statements. control flow rather than data flow carries tainted information. rather. Untainted data has the identity (null) taint code.htm (8 of 10) [30/08/2003 9:34:03 PM] . the following statement removes taint from a property so that a script can send it to another server: untaintedStat=untaint(window. For details on taint and untaint. Removing taint from the accumulator results in the accumulator having only the identity taint code. JavaScript adds the current document's taint code to the accumulator. If a window's taint accumulator holds taint and the script attempts to pass data over the network. All windows loading documents from the same origin share a taint accumulator. each window has a taint accumulator. You can add taint to or remove taint from a window's taint accumulator. you can then display embedded plug-in file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic. or serverC). The taint accumulator is reset to identity only if it contains the current document's original taint code. Accumulated taint propagates across setTimeout and into the evaluation of the first argument to setTimeout. see "taint" and "untaint". To remove taint from a window. the taint codes in the accumulator are checked.htm For example. call untaint with no argument. Only if the accumulated script taint. If the script. To handle these cases. The taint accumulator holds taint tested in the condition portion of if. q q To add taint to a window. a dialog box is displayed so the user can confirm or cancel the URL load or form post. serverB. so that a malicious script cannot signal private information such as session history by generating an HTML tag with an implicitly-loaded URL SRC parameter such as the following: document. The mark is called a taint code.defaultStatus) // untaintedStat can now be sent in a URL or form post by other scripts Neither taint nor untaint modifies its argument.bin/fake-img?" + encode(history) + ">") Determining installed plug-ins You can use JavaScript to determine whether a user has installed a particular plug-in. for. and data taints are incompatible. call taint with no argument.

description.mimeTypes["image/jpeg"].enabledPlugin null The following script checks to see whether the client is capable of displaying QuickTime movies.filename navigator. see the corresponding reference topics in Part 3.name Value LiveAudio navigator.writeln("Click <A HREF='movie. jpg." The navigator object has two properties for checking installed plug-ins: the mimeTypes array and the plugins array. the following table summarizes the values for displaying JPEG images: Expression navigator. and description as well as an array of MimeType objects for the MIME types supported by that plug-in. "Reference. For example.description navigator.plugins['LiveAudio']. which has properties for its name. You can also determine whether a client is capable of handling a particular MIME (Multipart Internet Mail Extension) type. an image or text) if it is not. pjpeg. file name.") plugins array plugins is an array of all plug-ins currently installed on the client.writeln("Too bad. Each element of the array is a MimeType object.htm data if the plug-in is installed. pjp navigator. file extensions.suffixes Value image/jpeg JPEG Image jpeg. Each element of the array is a Plugin object.mimeTypes["video/quicktime"] if (myMimetype) document.htm (9 of 10) [30/08/2003 9:34:03 PM] . the following table summarizes the values for the LiveAudio plug-in: Expression navigator. var myMimetype = navigator. This section introduces the objects and properties needed for handling plug-ins and MIME types. via helper applications. jpe.DLL 7 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic. The user can obtain a list of installed plug-ins by choosing About Plug-ins from the Help menu. For example. which has properties for its type.mimeTypes["image/jpeg"].length d:\nettools\netscape\nav30\ Program\plugins\NPAUDIO. can't show you any movies.description) else document. jfif.qt'>here</A> to see a " + myMimetype. and enabled plugins.description LiveAudio . or by plug-ins). or display some alternative information (for example.Netscape Navigator sound playing component navigator.plugins['LiveAudio']. For more detailed information on these objects and properties.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic.mimeTypes["image/jpeg"].type navigator. mimeTypes array mimeTypes is an array of all MIME types supported by the client (either internally.plugins['LiveAudio'].plugins['LiveAudio'].mimeTypes["image/jpeg"].

description navigator.plugins['LiveAudio'][1].file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic.enabledPlugin.plugins['LiveAudio'][1]. aiff navigator.plugins['LiveAudio'][1].name LiveAudio The following script checks to see whether the Shockwave plug-in is installed and displays an embedded Shockwave movie if it is: var myPlugin = navigator.writeln("You don't have Shockwave installed!") file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/advtopic.type navigator.plugins['LiveAudio'][1].htm (10 of 10) [30/08/2003 9:34:03 PM] .plugins["Shockwave"] if (myPlugin) document.writeln("<EMBED SRC='Movie. the length property indicates that navigator. The property values for the second element of this array are as follows: Expression navigator.dir' HEIGHT=100 WIDTH=100>") else document.plugins['LiveAudio'] has an array of MimeType objects containing seven elements.suffixes Value audio/x-aiff AIFF aif.htm In the previous table.

enables you to perform useful functions with your applications. for example. and data types are converted automatically as needed during script execution. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ident.14159 Logical (Boolean) values. a special keyword denoting a null value This relatively small set of types of values. Data type conversion JavaScript is a loosely typed language.htm (1 of 5) [30/08/2003 9:34:04 PM] . and functions as procedures that your application can perform.. However. and literals his chapter discusses values that JavaScript recognizes and describes the fundamental building blocks of JavaScript expressions: variables and literals. such as 42 or 3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ident. Values JavaScript recognizes the following types of values: q q q q Numbers. answer = "Thanks for all the fish. for example. you can use the Date object and its methods to handle dates.htm Values. There is no explicit distinction between integer and real-valued numbers. either true or false Strings. So. this assignment does not cause an error message. or data types. Nor is there an explicit date data type in Navigator. That means you do not have to specify the data type of a variable when you declare it. you could define a variable as follows: var answer = 42 And later.." Because JavaScript is loosely typed. such as "Howdy!" null. variables. you could assign the same variable a string value. Objects and functions are the other fundamental elements in the language. You can think of objects as named containers for values.

subsequent characters can also be digits (0-9). letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase)." The first statement returns the string "The answer is 42. converting it to a number. A JavaScript identifier. x = 42 With the keyword var.htm (2 of 5) [30/08/2003 9:34:04 PM] . parseFloat converts a string to a floating-point number. Some examples of legal names are Number_hits. or name. Variable scope You can declare a variable in two ways: q q By simply assigning it a value. and _name. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ident. must start with a letter or underscore ("_"). Because JavaScript is case sensitive.htm In expressions involving numeric and string values. temp99. Variables You use variables as symbolic names for values in your application. if possible." JavaScript provides several special functions for manipulating string and numeric values: q q q eval attempts to evaluate a string representing any JavaScript literals or variables. see Chapter 9." The second statement returns the string "42 is the answer. JavaScript converts the numeric values to strings. "Built-in objects and functions. For example. for example. You give variables names by which you refer to them and which must conform to certain rules.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ident. if possible." For more information on these functions. var x = 42 When you set a variable identifier by assignment outside of a function. it is called a global variable. for example. consider the following statements: x = "The answer is " + 42 y = 42 + " is the answer. parseInt converts a string to an integer of the specified radix (base).

A decimal integer literal consists of a sequence of digits without a leading 0 (zero). and -345.1415.htm because it is available everywhere in the current document. For example.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ident. not variables."). an exponent. Floating-point literals A floating-point literal can have the following parts: a decimal integer.htm (3 of 5) [30/08/2003 9:34:04 PM] . a leading 0x (or 0X) indicates hexadecimal. . -3. you can refer to this variable from a child frame as parent. "Using windows and frames. A floating-point literal must have at least one digit. Literals You use literals to represent values in JavaScript. Hexadecimal integers can include digits (0-9) and the letters a-f and A-F. When you declare a variable within a function. These are fixed values. Some examples of floating-point literals are 3. hexadecimal (base 16). but you need to use it if you want to declare a local variable inside a function that has already been declared as a global variable." You can access global variables declared in one window or frame from another window or frame by specifying the window or frame name. a decimal point (". it is called a local variable. because it is available only within the function.phoneNumber. if a variable called phoneNumber is declared in a FRAMESET document. The exponent part is an "e" or "E" followed by an integer. that you literally provide in your script. For information on using variables across frames and windows. a fraction (another decimal number).1e12. Integers Integers can be expressed in decimal (base 10). plus either a decimal point or "e" (or "E"). and 2E-12 Boolean literals file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ident. Some examples of integer literals are: 42 0xFFF. see Chapter 3. A leading 0 (zero) on an integer literal indicates it is in octal. Octal integers can include only the digits 0-7. Using var is optional. and octal (base 8). and a type suffix. which can be signed (preceded by "+" or "-").1E12.

var quote = "He read \"The Cremation of Sam McGee\" by R. as shown in the last element in the preceding list. Character Meaning \b \f \n \r \t \\ backspace form feed new line carriage return tab backslash character Escaping characters For characters not listed in the preceding table. A string must be delimited by quotation marks of the same type. For example. This is known as escaping the quotation marks. a preceding backslash is ignored." document. you can also include special characters in strings.W.write(quote) The result of this would be file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ident. String literals A string literal is zero or more characters enclosed in double (") or single (') quotation marks.htm The Boolean type has two literal values: true and false. The following table lists the special characters that you can use in JavaScript strings. with the exception of a quotation mark and the backslash character itself. The following are examples of string literals: q q q q "blah" 'blah' "1234" "one line \n another line" In addition to ordinary characters. either both single quotation marks or double quotation marks.htm (4 of 5) [30/08/2003 9:34:04 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ident. You can insert quotation marks inside strings by preceding them with a backslash. that is. Service.

htm He read "The Cremation of Sam McGee" by R. Service.htm (5 of 5) [30/08/2003 9:34:04 PM] . you must escape the backslash character. For example. to assign the file path c:\temp to a string.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ident. To include a literal backslash inside a string.W. use the following: var home = "c:\\temp" file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ident.

variables that have not been assigned a value are undefined and will cause a runtime error if used as numbers or as numeric variables. "Fred" or "234" Logical: evaluates to true or false The special keyword null denotes a null value.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr. it does not perform an assignment. for example. the following code executes the function myFunction because the array element is not defined: myArray=new Array() if (!myArray["notThere"]) myFunction() Conditional expressions A conditional expression can have one of two values based on a condition. You can use a file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr. the expression has the value of val1. however. The syntax is (condition) ? val1 : val2 If condition is true. including assignment. comparison. the value can be a number. or a logical value. Conceptually. For example. variables. and special operators. This expression itself evaluates to seven. In contrast. string. and those that simply have a value. there are two types of expressions: those that assign a value to a variable. evaluate to false. JavaScript has the following types of expressions: q q q Arithmetic: evaluates to a number. Otherwise it has the value of val2. Array elements that have not been assigned a value.14159 String: evaluates to a character string. a string. Such expressions use assignment operators. arithmetic. logical. the expression 3 + 4 simply evaluates to seven. bitwise. The operators used in such expressions are referred to simply as operators. for example 3. the expression x = 7 is an expression that assigns x the value seven. For example. On the other hand.htm Expressions and operators his chapter describes JavaScript expressions and operators.htm (1 of 10) [30/08/2003 9:34:05 PM] . operators. Expressions An expression is any valid set of literals. and expressions that evaluates to a single value.

x++ or ++x. and special operators. The basic assignment operator is equal (=). it assigns the value "minor" to status. For example. There are both binary and unary operators. comparison. arithmetic.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr. bitwise. 3+4 or x*y. Operators JavaScript has assignment. This section describes the operators and contains information about operator precedence. string. Assignment operators Implemented in Navigator 2. x = y assigns the value of y to x.htm (2 of 10) [30/08/2003 9:34:05 PM] . file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr.0 An assignment operator assigns a value to its left operand based on the value of its right operand. one before the operator and one after the operator: operand1 operator operand2 For example. which assigns the value of its right operand to its left operand.htm conditional expression anywhere you would use a standard expression. A unary operator requires a single operand. either before or after the operator: operator operand or operand operator For example. A binary operator requires two operands. status = (age >= 18) ? "adult" : "minor" This statement assigns the value "adult" to the variable status if age is eighteen or greater. Otherwise. logical. That is.

the comparisons are based on the standard lexicographical ordering. x != y returns true if x is not equal to y. Returns true if left operand is less than or equal to right operand. Example x == y returns true if x equals y.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr. x > y returns true if x is greater than y. Arithmetic operators file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr.htm (3 of 10) [30/08/2003 9:34:05 PM] . Less than (<) Less than or equal (<=) Returns true if left operand is less than right x < y returns true if x is less than operand. y. than or equal to y. When used on string values.htm The other operators are shorthand for standard operations. The operands can be numerical or string values. Returns true if left operand is greater than right operand. Greater than or equal (>=) Returns true if left operand is greater than or x >= y returns true if x is greater equal to right operand. x <= y returns true if x is less than or equal to y. Operator Equal (= =) Not equal (!=) Greater than (>) Description Returns true if the operands are equal. as shown in the following table: Shorthand operator Meaning x += y x -= y x *= y x /= y x %= y x <<= y x >>= y x >>>= y x &= y x ^= y x |= y x=x+y x=x-y x=x*y x=x/y x=x%y x = x << y x = x >> y x = x >>> y x=x&y x=x^y x=x|y Comparison operators Implemented in Navigator 2.0 A comparison operator compares its operands and returns a logical value based on whether the comparison is true or not. Returns true if the operands are not equal. They are described in the following table.

where var1 and var2 are variables.0 The decrement operator is used as follows: var-. and division (/). For example. The modulo function is the floating-point remainder of dividing var1 by var2. ++x). Modulus (%) Implemented in Navigator 2. then it returns the value after file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr. 12 % 5 returns 2. with operator after operand (for example. Decrement (--) Implemented in Navigator 2.0 The increment operator is used as follows: var++ or ++var This operator increments (adds one to) its operand and returns a value.htm (4 of 10) [30/08/2003 9:34:05 PM] . multiplication (*). var1 modulo var2. then the statement y = x++ sets y to three and increments x to four. subtraction (-). in the preceding statement. then it returns the value before decrementing. x++).0 The modulus operator is used as follows: var1 % var2 The modulus operator returns the first operand modulo the second operand. if x is three. then it returns the value after incrementing. then the statement y = ++x increments x to four and sets y to four.or --var This operator decrements (subtracts one from) its operand and returns a value. If x is three. For example. then it returns the value before incrementing. The standard arithmetic operators are addition (+).htm Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value. If used postfix (for example. If used prefix with operator before operand (for example. x-). If used prefix (for example.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr. Increment (++) Implemented in Navigator 2. If used postfix. --x). that is. These operators work as they do in other programming languages.

0 The unary negation precedes its operand and negates it. discarding bits shifted off. hexadecimal. or octal numbers. For example.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr. Returns a one in a bit position if bits of one but not both operands are one. For example. then the statement y = --x decrements x to two and sets y to two. Bitwise operators perform their operations on such binary representations.htm (5 of 10) [30/08/2003 9:34:05 PM] . Returns a one in a bit if bits of either operand is one. Bitwise operators Bitwise operators treat their operands as a set of bits (zeros and ones). If x is three. rather than as decimal. if x were three. if x is three. Flips the bits of its operand. discarding bits shifted off.0 The bitwise logical operators work conceptually as follows: q The operands are converted to thirty-two-bit integers and expressed by a series of bits (zeros and ones). then the statement y = x-. and shifting in zeros from the left. the decimal number nine has a binary representation of 1001. Bitwise logical operators Implemented in Navigator 2. Unary negation (-) Implemented in Navigator 2. that is. Zero-fill right shift a >>> b Shifts a in binary representation b bits to the right. The following table summarizes JavaScript's bitwise operators Operator Bitwise AND Bitwise OR Bitwise XOR Bitwise NOT Left shift Usage a&b a|b a^b ~a Description Returns a one in each bit position if bits of both operands are ones.htm decrementing. it would become -3. For example. shifting in zeros from the right. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr.sets y to three and decrements x to two. Sign-propagating right shift a >> b Shifts a in binary representation b bits to right. but they return standard JavaScript numerical values. x = -x negates the value of x. a << b Shifts a in binary representation b bits to left.

9<<2 yields thirty-six. which is thirtysix. and the second specifies the number of bit positions by which the first operand is to be shifted. Shift operators convert their operands to thirty-two-bit integers and return a result of the same type as the left operator. Excess bits shifted off to the right are discarded. Left shift This operator shifts the first operand the specified number of bits to the left. Sign-propagating right shift This operator shifts the first operand the specified number of bits to the right. 9>>2 yields -3. which is two. because 1001 shifted two bits to the left becomes 100100. because the sign is preserved. Zero bits are shifted in from the left.htm (6 of 10) [30/08/2003 9:34:05 PM] . The operator is applied to each pair of bits. the binary representation of nine is 1001.htm q q Each bit in the first operand is paired with the corresponding bit in the second operand: first bit to first bit. and so on. and the result is constructed bitwise. when the bitwise operators are applied to these values. 9>>2 yields two. Zero-fill right shift This operator shifts the first operand the specified number of bits to the right. Excess bits shifted off to the left are discarded. Excess bits shifted off to the right are discarded. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr. Likewise.0 The bitwise shift operators take two operands: the first is a quantity to be shifted. For example. Zero bits are shifted in from the right. For example. So.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr. second bit to second bit. because 1001 shifted two bits to the right becomes 10. and the binary representation of fifteen is 1111. The direction of the shift operation is controlled by the operator used. the results are as follows: q q q 15 & 9 yields 9 (1111 & 1001 = 1001) 15 | 9 yields 15 (1111 | 1001 = 1111) 15 ^ 9 yields 6 (1111 ^ 1001 = 0110) Bitwise shift operators Implemented in Navigator 2. For example. Copies of the leftmost bit are shifted in from the left.

Operator Usage Description and (&&) expr1 && expr2 Returns true if both logical expressions expr1 and expr2 are true. Short-circuit evaluation As logical expressions are evaluated left to right. "my " + "string" returns the string "my string"." then the expression mystring += "bet" evaluates to "alphabet" and assigns this value to mystring. zero-fill right shift and sign-propagating right shift yield the same result. which is four. For non-negative numbers. String operators Implemented in Navigator 2. Otherwise. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr. so any side effects of doing so do not take effect.htm (7 of 10) [30/08/2003 9:34:05 PM] . which can be used on string values. If both are false. 19>>>2 yields four. returning another string that is the union of the two operand strings. For example. if the variable mystring has the value "alpha. the concatenation operator (+) concatenates two string values together. if expr is false. They are described in the following table. Logical operators Implemented in Navigator 2. The rules of logic guarantee that these evaluations are always correct. For example.htm For example. If expr is true. returns true. or (||) not (!) expr1 || expr2 !expr Returns true if either logical expression expr1 or expr2 is true. The shorthand assignment operator += can also be used to concatenate strings. they are tested for possible "short-circuit" evaluation using the following rules: q q false && anything is short-circuit evaluated to false.0 In addition to the comparison operators. returns false. because 10011 shifted two bits to the right becomes 100. returns false. returns false. true || anything is short-circuit evaluated to true. Note that the anything part of the above expressions is not evaluated.0 Logical operators take Boolean (logical) values as operands and return a Boolean value.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr.

or String. Date.paramN] ) For more information. the typeof operator returns the following results: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr. Number. typeof Implemented in Navigator 3. Boolean. Math. operand is the string.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr.htm (8 of 10) [30/08/2003 9:34:05 PM] .[..0 You can use the new operator to create an instance of a user-defined object type or of one of the built-in object types Array. variable. typeof (operand) The typeof operator returns a string indicating the type of the unevaluated operand. see "new". keyword.htm Special operators new Implemented in Navigator 2.. Function. Suppose you define the following variables: var var var var myFun = new Function("5+2") shape="round" size=1 today=new Date() The typeof operator returns the following results for these variables: typeof typeof typeof typeof typeof myFun is object shape is string size is number today is object dontExist is undefined For the keywords true and null. Use new as follows: objectName = new objectType ( param1 [. or object for which the type is to be returned.0 The typeof operator is used in either of the following ways: 1. The parentheses are optional. typeof operand 2.param2] .

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr.htm

typeof true is boolean typeof null is object For a number or string, the typeof operator returns the following results: typeof 62 is number typeof 'Hello world' is string For property values, the typeof operator returns the type of value the property contains: typeof document.lastModified is string typeof window.length is number typeof Math.LN2 is number For methods and functions, the typeof operator returns results as follows: typeof typeof typeof typeof blur is function eval is function parseInt is function shape.split is function

For objects, the typeof operator returns results as follows: typeof typeof typeof typeof typeof Date is function Function is function Math is function Option is function String is function

void
Implemented in Navigator 3.0 The void operator is used in either of the following ways: 1. javascript:void (expression) 2. javascript:void expression The void operator specifies an expression to be evaluated without returning a value. expression is a JavaScript expression to evaluate. The parentheses surrounding the expression are optional, but it is good style to use them. You can use the void operator to specify an expression as a hypertext link. The expression is evaluated but is
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr.htm (9 of 10) [30/08/2003 9:34:05 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr.htm

not loaded in place of the current document. The following code creates a hypertext link that does nothing when the user clicks it. When the user clicks the link, void(0) evaluates to 0, but that has no effect in JavaScript. <A HREF="javascript:void(0)">Click here to do nothing</A> The following code creates a hypertext link that submits a form when the user clicks it. <A HREF="javascript:void(document.form.submit())">Click here to submit</A> For information on creating hypertext links, see "Area" and "Link object".

Operator precedence
The precedence of operators determines the order they are applied when evaluating an expression. You can override operator precedence by using parentheses. The following table describes the precedence of operators, from lowest to highest:

Operator assignment conditional logical-or logical-and bitwise-or bitwise-xor bitwise-and equality relational bitwise shift multiply/divide call, member

Examples = += -= *= /= %= <<= >>= >>>= &= ^= |= ?: || && | ^ & == != < <= > >= << >> >>> * / % () [] .

addition/subtraction + negation/increment ! ~ - ++ -- typeof void

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/expr.htm (10 of 10) [30/08/2003 9:34:05 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm

Object model
avaScript is based on a simple object-oriented paradigm. An object is a construct with properties that are JavaScript variables or other objects. An object also has functions associated with it that are known as the object's methods. In addition to objects that are built into the Navigator client and the LiveWire server, you can define your own objects. This chapter describes how to use objects, properties, functions, and methods, and how to create your own objects.

Objects and properties
A JavaScript object has properties associated with it. You access the properties of an object with a simple notation: objectName.propertyName Both the object name and property name are case sensitive. You define a property by assigning it a value. For example, suppose there is an object named myCar (for now, just assume the object already exists). You can give it properties named make, model, and year as follows: myCar.make = "Ford" myCar.model = "Mustang" myCar.year = 69; An array is an ordered set of values associated with a single variable name. Properties and arrays in JavaScript are intimately related; in fact, they are different interfaces to the same data structure. So, for example, you could access the properties of the myCar object as follows: myCar["make"] = "Ford" myCar["model"] = "Mustang" myCar["year"] = 67 This type of array is known as an associative array, because each index element is also associated with a string value. To illustrate how this works, the following function displays the properties of the object when you pass the object and the object's name as arguments to the function:

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm (1 of 10) [30/08/2003 9:34:05 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm

function show_props(obj, obj_name) { var result = "" for (var i in obj) result += obj_name + "." + i + " = " + obj[i] + "\n" return result } So, the function call show_props(myCar, "myCar") would return the following: myCar.make = Ford myCar.model = Mustang myCar.year = 67

Functions
Functions are one of the fundamental building blocks in JavaScript. A function is a JavaScript procedure--a set of statements that performs a specific task. To use a function, you must first define it; then your script can call it.

Defining functions
A function definition consists of the function keyword, followed by
q q q

The name of the function. A list of arguments to the function, enclosed in parentheses and separated by commas. The JavaScript statements that define the function, enclosed in curly braces, { }. The statements in a function can include calls to other functions defined in the current application.

In Navigator JavaScript, it is good practice to define all your functions in the HEAD of a page so that when a user loads the page, the functions are loaded first. For example, here is the definition of a simple function named pretty_print: function pretty_print(str) { document.write("<HR><P>" + str) } This function takes a string, str, as its argument, adds some HTML tags to it using the concatenation operator (+), and then displays the result to the current document using the write method.
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm (2 of 10) [30/08/2003 9:34:05 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm

In addition to defining functions as described here, you can also define Function objects, as described in "Function object".

Using functions
In a Navigator application, you can use (or call) any function defined in the current page. You can also use functions defined by other named windows or frames; for more information, see Chapter 3, "Using windows and frames." In a LiveWire application, you can use any function compiled with the application. Defining a function does not execute it. You have to call the function for it to do its work. For example, if you defined the example function pretty_print in the HEAD of the document, you could call it as follows: <SCRIPT> pretty_print("This is some text to display") </SCRIPT> The arguments of a function are not limited to strings and numbers. You can pass whole objects to a function, too. The show_props function (defined in "Objects and properties") is an example of a function that takes an object as an argument. A function can even be recursive, that is, it can call itself. For example, here is a function that computes factorials: function factorial(n) { if ((n == 0) || (n == 1)) return 1 else { result = (n * factorial(n-1) ) return result } } You could then display the factorials of one through five as follows: for (x = 0; x < 5; x++) { document.write("<BR>", x, " factorial is ", factorial(x)) } The results are:

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm (3 of 10) [30/08/2003 9:34:05 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm

0 factorial is 1 1 factorial is 1 2 factorial is 2 3 factorial is 6 4 factorial is 24 5 factorial is 120

Using the arguments array
The arguments of a function are maintained in an array. Within a function, you can address the parameters passed to it as follows: functionName.arguments[i] where functionName is the name of the function and i is the ordinal number of the argument, starting at zero. So, the first argument passed to a function named myfunc would be myfunc.arguments[0]. The total number of arguments is indicated by the variable arguments.length. Using the arguments array, you can call a function with more arguments than it is formally declared to accept using. This is often useful if you don't know in advance how many arguments will be passed to the function. You can use arguments.length to determine the number of arguments actually passed to the function, and then treat each argument using the arguments array. For example, consider a function defined to create HTML lists. The only formal argument for the function is a string that is "U" for an unordered (bulleted) list or "O" for an ordered (numbered) list. The function is defined as follows: function list(type) { document.write("<" + type + "L>") // begin list // iterate through arguments for (var i = 1; i < list.arguments.length; i++) document.write("<LI>" + list.arguments[i]) document.write("</" + type + "L>") // end list } You can pass any number of arguments to this function, and it will then display each argument as an item in the indicated type of list. For example, the following call to the function list("o", "one", 1967, "three", "etc., etc...") results in this output:

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm (4 of 10) [30/08/2003 9:34:05 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm

1.one 2.1967 3.three 4.etc., etc...

Creating new objects
Both client and server JavaScript have a number of predefined objects. In addition, you can create your own objects. Creating your own object requires two steps: 1. Define the object type by writing a constructor function. 2. Create an instance of the object with new. To define an object type, create a function for the object type that specifies its name, properties, and methods. For example, suppose you want to create an object type for cars. You want this type of object to be called car, and you want it to have properties for make, model, year, and color. To do this, you would write the following function: function car(make, model, year) { this.make = make this.model = model this.year = year } Notice the use of this to assign values to the object's properties based on the values passed to the function. Now you can create an object called mycar as follows: mycar = new car("Eagle", "Talon TSi", 1993) This statement creates mycar and assigns it the specified values for its properties. Then the value of mycar.make is the string "Eagle," mycar.year is the integer 1993, and so on. You can create any number of car objects by calls to new. For example, kenscar = new car("Nissan", "300ZX", 1992) An object can have a property that is itself another object. For example, suppose you define an object called person as follows:
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm (5 of 10) [30/08/2003 9:34:05 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm

function person(name, age, sex) { this.name = name this.age = age this.sex = sex } and then instantiate two new person objects as follows: rand = new person("Rand McKinnon", 33, "M") ken = new person("Ken Jones", 39, "M") Then you can rewrite the definition of car to include an owner property that takes a person object, as follows: function car(make, model, year, owner) { this.make = make this.model = model this.year = year this.owner = owner } To instantiate the new objects, you then use the following: car1 = new car("Eagle", "Talon TSi", 1993, rand) car2 = new car("Nissan", "300ZX", 1992, ken) Notice that instead of passing a literal string or integer value when creating the new objects, the above statements pass the objects rand and ken as the arguments for the owners. Then if you want to find out the name of the owner of car2, you can access the following property: car2.owner.name Note that you can always add a property to a previously defined object. For example, the statement car1.color = "black" adds a property color to car1, and assigns it a value of "black." However, this does not affect any other objects. To add the new property to all objects of the same type, you have to add the property to the definition of the car object type.

Indexing object properties
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm (6 of 10) [30/08/2003 9:34:05 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm

In Navigator 2.0, you can refer to an object's properties by their property name or by their ordinal index. In Navigator 3.0, however, if you initially define a property by its name, you must always refer to it by its name, and if you initially define a property by an index, you must always refer to it by its index. This applies when you create an object and its properties with a constructor function, as in the above example of the Car object type, and when you define individual properties explicitly (for example, myCar.color = "red"). So if you define object properties initially with an index, such as myCar[5] = "25 mpg", you can subsequently refer to the property as myCar[5]. The exception to this rule is objects reflected from HTML, such as the forms, array. You can always refer objects in these arrays by either their ordinal number (based on where they appear in the document) or their name (if defined). For example, if the second <FORM> tag in a document has a NAME attribute of "myForm", you can refer to the form as document.forms[1] or document.forms["myForm"] or document.myForm.

Defining properties for an object type
You can add a property to a previously defined object type by using the prototype property. This defines a property that is shared by all objects of the specified type, rather than by just one instance of the object. The following code adds a color property to all objects of type car, and then assigns a value to the color property of the object car1. For more information, see "prototype". Car.prototype.color=null car1.color="black" birthday.description="The day you were born"

Defining methods
A method is a function associated with an object. You define a method the same way you define a standard function. Then you use the following syntax to associate the function with an existing object: object.methodname = function_name where object is an existing object, methodname is the name you are assigning to the method, and function_name is the name of the function. You can then call the method in the context of the object as follows: object.methodname(params);

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm (7 of 10) [30/08/2003 9:34:05 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm

You can define methods for an object type by including a method definition in the object constructor function. For example, you could define a function that would format and display the properties of the previously-defined car objects; for example, function displayCar() { var result = "A Beautiful " + this.year + " " + this.make + " " + this.model pretty_print(result) } where pretty_print is the function (defined in "Functions") to display a horizontal rule and a string. Notice the use of this to refer to the object to which the method belongs. You can make this function a method of car by adding the statement this.displayCar = displayCar; to the object definition. So, the full definition of car would now look like function car(make, model, year, owner) { this.make = make this.model = model this.year = year this.owner = owner this.displayCar = displayCar } Then you can call the displayCar method for each of the objects as follows: car1.displayCar() car2.displayCar() This will produce output like:

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.htm (8 of 10) [30/08/2003 9:34:05 PM]

value < lowval) || (obj. The button's onClick event handler uses this.htm (9 of 10) [30/08/2003 9:34:05 PM] . When combined with the form property. this can refer to the current object's parent form.text1.htm Using this for object references JavaScript has a special keyword.form. using this to pass it the form element.form to refer to the parent form.value=this. that you can use within a method to refer to the current object.form. this refers to the calling object in a method. suppose you have a function called validate that validates an object's value property.name"> </FORM> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model. you could call validate in each form element's onChange event handler.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model. given the object and the high and low values: function validate(obj. In the following example. as in the following example: <INPUT TYPE = "text" NAME = "age" SIZE = 3 onChange="validate(this. this. lowval. hival) { if ((obj. When the user clicks the button. myForm.value > hival)) alert("Invalid Value!") } Then. the form myForm contains a Text object and a button. 99)"> In general. the value of the Text object is set to the form's name. For example. 18. <FORM NAME="myForm"> Form name:<INPUT TYPE="text" NAME="text1" VALUE="Beluga"> <P> <INPUT NAME="button1" TYPE="button" VALUE="Show Form Name" onClick="this.

JavaScript finalizes the object immediately. you can remove an object by setting its object reference to null (if that is the last reference to the object).0. as part of the assignment expression.0.htm (10 of 10) [30/08/2003 9:34:05 PM] . file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model. you cannot remove objects--they exist until you leave the page containing the object. In JavaScript for Navigator 3.htm Object deletion In JavaScript for Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/model.

element1. emp[2] employee number two.htm (1 of 13) [30/08/2003 9:34:06 PM] . Date.. elementn is a list of values for the array's elements. For example. Function. and String. An array is an ordered set of values that you reference through a name and an index. arrayObjectName = new Array([arrayLength]) 2. . When this form is specified. Built-in objects The built-in objects are Array.. It has a property for determining the array length. the array is initalized with the specified values as its elements. Number. Math. The Array object has the following methods: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. arrayObjectName is either the name of an existing Array object or a property of an existing object. Array object JavaScript does not have an explicit array data type. The Array object has methods for joining. and the array's length property is set to the number of arguments.. you could have an array called emp that contains employees' names indexed by their employee number. However. arrayObjectName = new Array([element0. When using Array properties and methods. and sorting arrays. "Using Navigator objects. To create an Array object: 1.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. arrayLength is the initial length of the array. Boolean.htm Built-in objects and functions everal objects are built in to JavaScript and can be used in either client or server scripts. and so on. So emp[1] would be employee number one. You can access this value using the length property. These objects are in addition to LiveWire objects defined for server-side JavaScript and Navigator objects introduced in Chapter 2. elementn]) arrayObjectName is either the name of a new object or a property of an existing object." A handful of built-in functions can also be used in both client and server scripts. you can use the built-in Array object and its methods to work with arrays in your applications. reversing.

sort sorts the array so that myArray[0] is "Fire". j++) { str += a[i][j] } document. suppose you define the following array: myArray = new Array("Wind". myVar. myArray[1] is "Rain".htm (2 of 13) [30/08/2003 9:34:06 PM] . j < 4.write(str. i < 4. j++) { a[i][j] = "["+i+".file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. emp[1] = "Casey Jones" emp[2] = "Phil Lesh" emp[3] = "August West" You can also populate an array when you create it: myArray = new Array("Hello".Rain.reverse transposes the array so that myArray[0] is "Fire". 3.Fire". i++) { a[i] = new Array(4) for (j=0. and myArray[2] is "Wind". myArray. myArray. For example. myArray."+j+"]" } } for (i=0.join() returns "Wind."<p>") } file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. and myArray[2] is "Wind". a = new Array(4) for (i=0.htm q q q join joins all elements of an array into a string reverse transposes the elements of an array: the first array element becomes the last and the last becomes the first sort sorts the elements of an array For example. myArray[1] is "Rain". i++) { str = "Row "+i+":" for (j=0."Rain". Populating an array You can populate an array by assigning values to its elements. i < 4. j < 4.14159) The following code creates a two-dimensional array and displays the results."Fire") myArray.

3] Row 2:[2. booleanObjectName is either the name of an existing Boolean object or a property of an existing object.2][2. JavaScript returns the primitive value of the Boolean object by automatically invoking the valueOf method. if necessary.3] Row 3:[3. false. When using Boolean properties.2][0.0][0. Boolean object Use the built-in Boolean object when you need to convert a non-boolean value to a boolean value. null.3] Row 1:[1.htm This example displays the following results: Multidimensional array test Row 0:[0. value is the initial value of the Boolean object. You can use the Boolean object any place JavaScript expects a primitive boolean value.3] Referring to array elements You can refer to an array's elements by using the element's value or ordinal number.0][1."Rain". The following examples create Boolean objects: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. suppose you define the following array: myArray = new Array("Wind".htm (3 of 13) [30/08/2003 9:34:06 PM] . or the empty string "". including the string "false" create an object with an initial value of true.1][2.0][2.2][3. The value is converted to a boolean value. To create a Boolean object: booleanObjectName = new Boolean(value) booleanObjectName is either the name of a new object or a property of an existing object.2][1."Fire") You can then refer to the first element of the array as myArray[0] or myArray["Wind"]. If value is omitted or is 0. it the object has an initial value of false.1][3.1][1. All other values. For example.0][3.1][0.

for setting date and time values in Date objects." For example. and both languages store dates as the number of milliseconds since January 1. A string representing a date in the following form: "Month day. To create a Date object: dateObjectName = new Date([parameters]) where dateObjectName is the name of the Date object being created. year hours:minutes:seconds. for parsing Date strings. or seconds. For example. getting. "to" methods. and seconds. If you omit hours. Xmas95 = new Date(95. For example. month.0). hour.11. minutes.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. day. you cannot work with dates prior to January 1. 1970. parse and UTC methods. The two languages have many of the same date methods.11. The parameters in the preceding syntax can be any of the following: q q q Nothing: creates today's date and time. and day. 00:00:00. 1970.30. minute. the value will be set to zero.htm bfalse = new Boolean(false) btrue = new Boolean(true) Date object JavaScript does not have a date data type. Note Currently. It does not have any properties. However. for getting date and time values from Date objects.25. today = new Date(). Xmas95 = new Date(95. and manipulating dates. month. "get" methods. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. for returning string values from Date objects.9. Methods of the Date object The Date object methods for handling dates and times fall into these broad categories: q q q q "set" methods. For example.25). JavaScript handles dates similarly to Java. 1995 13:30:00"). Xmas95 = new Date("December 25. it can be a new object or a property of an existing object. A set of integer values for year.htm (4 of 13) [30/08/2003 9:34:06 PM] . The Date object has a large number of methods for setting. you can use the Date object and its methods to work with dates and times in your applications. A set of values for year.

it computes the number of days between today and endYear. It then creates a Date object named endYear and sets the year to the current year.getTime()) / msPerDay daysLeft = Math. 1990") // Set day and month endYear. For example.htm (5 of 13) [30/08/2003 9:34:06 PM] . minutes. For example. The getTime and setTime methods are useful for comparing dates. and years separately. 1995") Then Xmas95. The parse method is useful for assigning values from date strings to existing Date objects. day of the month. months.today. hours. There is a getDay method that returns the day of the week. and Xmas95. the following code displays the number of days left in the current year: today = new Date() endYear = new Date("December 31. using the number of milliseconds per day.setYear(today.getTime() . day of the week. suppose you define the following date: Xmas95 = new Date("December 25.round(daysLeft) document. the following code uses parse and setTime to assign a date value to the IPOdate object: IPOdate = new Date() IPOdate.write("Number of days left in the year: " + daysLeft) This example creates a Date object named today that contains today's date. The getTime method returns the number of milliseconds since the epoch for a Date object. but no corresponding setDay method.getYear() returns 95.getMonth() returns 11. because the day of the week is set automatically.getYear()) // Set year to this year msPerDay = 24 * 60 * 60 * 1000 // Number of milliseconds per day daysLeft = (endYear. Then.parse("Aug 9.htm With the "get" and "set" methods you can get and set seconds. These methods use integers to represent these values as follows: q q q q q q Seconds and minutes: 0 to 59 Hours: 0 to 23 Day: 0 to 6 (day of the week) Date: 1 to 31 (day of the month) Months: 0 (January) to 11 (December) Year: years since 1900 For example. 1995")) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. using getTime and rounding to a whole number of days.setTime(Date.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin.

A form called clockForm includes a single text field named digits.htm Using the Date object: an example The following example shows a simple application of Date: it displays a continuously-updated digital clock in an HTML text field.htm (6 of 13) [30/08/2003 9:34:06 PM] ." document." : " A.BODY&GT: of the document is: <BODY ONLOAD="JSClock()"> <FORM NAME="clockForm"> The current time is <INPUT TYPE="text" NAME="digits" SIZE=12 VALUE=""> </FORM> </BODY> The <BODY> tag includes an onLoad event handler.digits. When the page loads. The display in Navigator looks like this: JavaScript clock The current time is The &LT. defined in the <HEAD>. the event handler calls the function JSClock.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin.1000) } //--> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. which you cannot update without reloading the document). whose value is initially an empty string.M. The <HEAD> of the document defines JSClock as follows: <HEAD> <SCRIPT language="JavaScript"> <!-function JSClock() { var time = new Date() var hour = time.value = temp id = setTimeout("JSClock()".M.getMinutes() var second = time.getHours() var minute = time.12 : hour) temp += ((minute < 10) ? ":0" : ":") + minute temp += ((second < 10) ? ":0" : ":") + second temp += (hour >= 12) ? " P.getSeconds() var temp = "" + ((hour > 12) ? hour .clockForm. This is possible because you can dynamically change the contents of a text field with JavaScript (in contrast to ordinary text.

The first statement creates a variable temp. in this case a call to JSClock. otherwise simply hour. The final statement in the function is a recursive call to JSClock: id = setTimeout("JSClock()". The next statement assigns the value of temp to the text field: document. assigning it a value using a conditional expression. Note that the function returns a value (assigned to id). Function object The built-in Function object specifies a string of JavaScript code to be compiled as a function. getMinutes.aform. if hour is greater than 12. and second. (hour .000 milliseconds (one second). and getSeconds methods assign the value of the current hour. otherwise. This updates the display of time in the form at one-second intervals. otherwise it adds a string with a demarcating colon.htm (7 of 13) [30/08/2003 9:34:06 PM] . it appends "AM" to temp.digits.13). minute. 1000) The built-in JavaScript setTimeout function specifies a time delay to evaluate an expression. The next statement appends a minute value to temp. The next four statements build a string value based on the time.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. since no arguments are given. Then a statement appends a seconds value to temp in the same way.value = temp This displays the time string in the document. the conditional expression adds a string with a preceding zero. To create a Function object: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. If the value of minute is less than 10. a conditional expression appends "PM" to temp if hour is 12 or greater. used only as an identifier (which can be used by the clearTimeout method to cancel the evaluation). Finally.htm </SCRIPT> </HEAD> The JSClock function first creates a new Date object called time. The second argument indicates a a delay of 1. Then calls to the getHours. time is created with the current date and time. minute and seconds to hour.

colorButton. document.. you can specify the variable name as if it were a function. arg2.htm functionObjectName = new Function ([arg1. . Function objects are evaluated each time they are used. <INPUT NAME="colorButton" TYPE="button" VALUE="Change background color" onClick="setBGColor()"> Creating the variable setBGColor shown above is similar to declaring the following function: function setBGColor() { document... Each must be a string that corresponds to a valid JavaScript identifier. argn are arguments to be used by the function as formal argument names. . as described in "function". When using Function properties.onclick=setBGColor 2. This is less efficient than declaring a function and calling it within your code. argn].. functionBody is a string specifying the JavaScript code to be compiled as the function body.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. because declared functions are compiled.bgColor='antiquewhite'") To call the Function object. The following code executes the function specified by the setBGColor variable: var colorChoice="antiquewhite" if (colorChoice=="antiquewhite") {setBGColor()} You can assign the function to an event handler in either of the following ways: 1. arg1. In addition to defining functions as described here. functionBody) functionObjectName is the name of a variable or a property of an existing object. This function sets the current document's background color. The following code assigns a function to the variable setBGColor.onerror. It can also be an object followed by a lowercase event handler name. such as window. for example "x" or "theForm". you can also use the function statement.bgColor='antiquewhite' } file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin.form1. arg2. var setBGColor = new Function("document. functionObjectName is either the name of an existing Function object or a property of an existing object.htm (8 of 13) [30/08/2003 9:34:06 PM] .

atan Inverse trigonometric functions... The following table summarizes Math's methods.). For example. but they have differences: q q When you assign a function to a variable using var setBGColor = new Function(". the Math object's PI property has the value of pi (3. second is exponent Rounds argument to nearest integer Square root acos. return values in radians file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. which you would use in an application as Math.. first argument is base. if you want to use the trigonometric function sine.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin.. log ceil floor min..htm (9 of 13) [30/08/2003 9:34:06 PM] . setBGColor is a variable for which the current value is a reference to the function created with new Function(). argument in radians Exponential and natural logarithm. cos. logarithmic. Math object The built-in Math object has properties and methods for mathematical constants and functions.. For example. you would write Math. Method abs sin. setBGColor is not a variable. These include trigonometric. asin. base e Returns least integer greater than or equal to argument Returns greatest integer less than or equal to argument Returns greater or lesser (respectively) of two arguments Exponential.sin(1. tan exp. and other functions.141. standard mathematical functions are methods of Math. max pow round sqrt Description Absolute value Standard trigonometric functions. it is the name of a function.htm Assigning a function to a variable is similar to declaring a function.PI Similarly.}. When you create a function using function setBGColor() {. exponential.56) Note that all trigonometric methods of Math take arguments in radians.").

To create a String object: stringObjectName = new String(string) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. The String object has a large number of methods for manipulating strings.htm (10 of 13) [30/08/2003 9:34:06 PM] .MAX_VALUE smallestNum = Number. You use these properties as follows: biggestNum = Number. For example.NEGATIVE_INFINITY notANum = Number. returned on overflow NEGATIVE_INFINITY Special infinite value. However.MIN_VALUE infiniteNum = Number. with (Math) a y x } { = PI * r*r = r*sin(theta) = r*cos(theta) Number object The Number object has properties for numerical constants. and infinity. so you don't have to type "Math" repeatedly. Method MAX_VALUE MIN_VALUE NaN POSITIVE_INFINITY Description The largest representable number The smallest representable number Special "not a number" value Special negative infinite value.POSITIVE_INFINITY negInfiniteNum = Number. such as maximum value.htm It is often convenient to use the with statement when a section of code uses several math constants and methods. not-a-number. you can use the String object and its methods to work with strings in your applications.NaN The following table summarizes Number's properties. returned on overflow String object JavaScript does not have a string data type.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. It has one property for determining the string's length.

9) returns the string "o.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. the expression x = mystring. World!" has 13 characters. string is any string. The substring method takes two arguments and returns a subset of the string between the two arguments. because "Hello. both mystring. length. strike. WORLD!". The String object also has a number of methods for automatic HTML formatting. A String object has two types of methods: those that return a variation on the string itself. fixed. sub.toUpperCase() and "hello. see the reference topic for substring.link("http://www. sup Creates HTML formatted string file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin.htm (11 of 13) [30/08/2003 9:34:07 PM] . Using the previous example.length assigns a value of 13 to x. such as substring and toUpperCase. italics. using the previous example. So.toUpperCase() return the string "HELLO. For example. using the previous example.substring(4. For example. A String object has one property. For example. and those that return an HTML-formatted version of the string. for example. world!". you could create a hyperlink to a hypothetical URL with the link method as follows: mystring.com") The following table summarizes the methods of String objects: Method anchor Description Creates HTML named anchor big. such as bold to create boldface text and link to create a hyperlink. such as bold and link. bold. the literal "Howdy" is a String object. blink. that indicates the number of characters in the string. the following statement creates a String object called mystring: mystring = new String ("Hello. World!") String literals are also String objects." For more information.helloworld.htm stringObjectName is the name of a new String object. small. Wo. mystring.

htm charAt indexOf.htm (12 of 13) [30/08/2003 9:34:07 PM] . the parseFloat and parseInt functions return "NaN" when they evaluate a value that is not a number.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. The syntax of isNaN is: isNaN(testValue) testValue is the value you want to evaluate. respectively Creates HTML hyperlink Splits a String object into an array of strings by separating the string into substrings Returns the specified subset of the string Returns the string in all lowercase or all uppercase. isNaN function The isNaN function evaluates an argument to determine if it is "NaN" (not a number)." and false otherwise. The following code evaluates floatValue to determine if it is a number and then calls a procedure accordingly: floatValue=parseFloat(toFloat) if (isNaN(floatValue)) { notFloat() } else { isFloat() file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. On platforms that support NaN. isNaN returns true if passed "NaN. respectively link split substring toLowerCase. lastIndexOf Returns the character at the specified position in string Returns the position of specified substring in the string or last position of specified substring. toUpperCase Built-in functions JavaScript has two "top-level" functions built in to the language: parseInt and parseFloat.

For radixes above ten." The parseInt function truncates numbers to integer values. radix]) parseInt parses its first argument. The syntax of parseFloat is parseFloat(str) parseFloat parses its argument. return a numeric value when given a string as an argument. A through F are used. and attempts to return a floating-point number. For example. the string str. the string str. a numeral (0-9). or an exponent. radix. parseInt and parseFloat. If the first character cannot be converted to a number in the specified radix. optional argument. for hexadecimal numbers (base 16). it returns "NaN" (not a number). a radix of ten indicates to convert to a decimal number. For example. and so on. indicated by the second. see the reference topics. it returns "NaN. sixteen hexadecimal. then it returns the value up to that point and ignores that character and all succeeding characters. The syntax of parseInt is parseInt(str [. eight octal.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. If parseInt encounters a character that is not a numeral in the specified radix. a decimal point. the letters of the alphabet indicate numerals greater than nine.htm } parseInt and parseFloat functions The two "parse" functions. and attempts to return an integer of the specified radix (base). For detailed descriptions and examples.htm (13 of 13) [30/08/2003 9:34:07 PM] . it ignores it and all succeeding characters and returns the integer value parsed up to that point. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/builtin. If it encounters a character other than a sign (+ or -). If the first character cannot be converted to a number.

threeChar.*/) The following sections provide a brief overview of each statement. new. function checkData () { if (document. otherwise. you must enclose the statements in curly braces.value + " is not valid.. this. Example.else Loop statements: for. the function checkData returns true if the number of characters in a Text object is three. The statements to be executed can be any JavaScript statements. Conditional statement Use the if statement to perform certain statements if a logical condition is true. including further nested if statements. it displays an alert and returns false. An if statement looks as follows: if (condition) { statements1 [ } else { statements2 ] } The condition can be any JavaScript expression that evaluates to true or false.in...value.htm Overview of JavaScript statements avaScript supports a compact set of statements that you can use to incorporate a great deal of interactivity in Web pages. {}. while. use the optional else clause to perform other statements if the condition is false.form1..htm (1 of 7) [30/08/2003 9:34:07 PM] . break.. See the statements reference for details. and with Comments: single-line (//) and multiline (/*.length == 3) { return true } else { alert("Enter exactly three characters. The statements fall into the following categories: q q q q Conditional statement: if.") return false } } file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov. If you want to use more than one statement after an if or else statement..form1. In the following example.threeChar.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov. " + document. and continue Object manipulation statements and operators: for.

If the value of condition is true. i++) { if (selectObject. A for statement looks as follows: for ([initial-expression]. <SCRIPT> function howMany(selectObject) { var numberSelected=0 for (var i=0. This expression usually initializes one or more loop counters. Example.selected==true) numberSelected++ } return numberSelected } </SCRIPT> <FORM NAME="selectForm"> <P><B>Choose some music types.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov. [increment-expression]) { statements } When a for loop executes. and increments i by one after each pass through the loop. performs the succeeding if statement. Another statement. It checks that i is less than the number of options in the Select object. the following occurs: 1. The JavaScript for loop is similar to the Java and C for loop. and control returns to step 2.htm Loop statements A loop is a set of commands that executes repeatedly until a specified condition is met. executes statements repeatedly but is used for object manipulation. The following function contains a for statement that counts the number of selected options in a scrolling list (a Select object that allows multiple selections). JavaScript supports two loop statements: for and while. The initializing expression initial-expression. The for statement declares the variable i and initializes it to zero. is executed. 3. i < selectObject. The update expression increment-expression executes.. then click the button below:</B> <BR><SELECT NAME="musicTypes" MULTIPLE> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov. if any. 2. In addition. the for loop terminates. for statement A for loop repeats until a specified condition evaluates to false. See "Object manipulation statements and operators". the loop statements execute.options[i]. but the syntax allows an expression of any degree of complexity.. [condition].in. If the value of condition is false.htm (2 of 7) [30/08/2003 9:34:07 PM] . The statements execute.options. The condition expression is evaluated. you can use the break and continue statements within loop statements.length. 4. for.

each time control passes through the loop.htm <OPTION> Classical <OPTION> Opera </SELECT> <P><INPUT TYPE="button" VALUE="How many are selected?" onClick="alert ('Number of options selected: ' + howMany(document. the statements within the loop stop executing and control passes to the statement following the loop. The statements in the following while loop execute forever because the condition never becomes false: while (true) { alert("Hello.htm (3 of 7) [30/08/2003 9:34:07 PM] .selectForm. world") } break statement file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov. so the loop terminates. x and n take on the following values: q q q After the first pass: n = 1 and x = 1 After the second pass: n = 2 and x = 3 After the third pass: n = 3 and x = 6 After completing the third pass. the condition test is not continuous but is performed once at the beginning of the loop and again just following the last statement in statements. That is. A while statement looks as follows: while (condition) { statements } If the condition becomes false. Example 2: infinite loop.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov. The condition test occurs only when the statements in the loop have been executed and the loop is about to be repeated. otherwise. Example 1. The following while loop iterates as long as n is less than three: n = 0 x = 0 while( n < 3 ) { n ++ x += n } With each iteration. the condition n < 3 is no longer true. the loop will never terminate. Make sure the condition in a loop eventually becomes false. Therefore. the loop increments n and adds that value to x.musicTypes))"> </FORM> while statement A while statement repeats a loop as long as a specified condition evaluates to true.

three. it jumps back to the condition. i = 0 n = 0 while (i < 5) { i++ if (i == 3) continue n += i } Object manipulation statements and operators JavaScript has several ways of manipulating objects: new operator.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov. The following example shows a while loop with a continue statement that executes when the value of i is three.htm The break statement terminates the current while or for loop and transfers program control to the statement following the terminated loop. and then returns the value 3 * x. continue does not terminate the execution of the loop entirely. A break statement looks as follows: break Example. it jumps to the increment-expression... function testBreak(x) { var i = 0 while (i < 6) { if (i == 3) break i++ } return i*x } continue statement A continue statement terminates execution of the block of statements in a while or for loop and continues execution of the loop with the next iteration. The following function has a break statement that terminates the while loop when i is three. seven. q q In a while loop. A continue statement looks as follows: continue In contrast to the break statement. for. Thus. this keyword.in statement. and twelve. Example. n takes on the values one. Instead. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov. In a for loop.htm (4 of 7) [30/08/2003 9:34:07 PM] . and with statement.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov.htm

new operator
You can use the new operator to create an instance of a user-defined object type or of one of the built-in object types Array, Boolean, Date, Function, Math, Number, or String. Use new as follows: objectName = new objectType ( param1 [,param2] ...[,paramN] ) The following example creates an Array object with 25 elements, then assigns values to the first three elements: musicTypes = new Array(25) musicTypes[0] = "R&B" musicTypes[1] = "Blues" musicTypes[2] = "Jazz" The following examples create several Date objects: today = new Date() birthday = new Date("December 17, 1995 03:24:00") birthday = new Date(95,12,17) The following example creates a user-define object type car, with properties for make, model, and year. The example then creates an object called mycar and assigns values to its properties. The value of mycar.make is the string "Eagle", mycar.year is the integer 1993, and so on. function car(make, model, year) { this.make = make this.model = model this.year = year } mycar = new car("Eagle", "Talon TSi", 1993) For more information on new, see "new".

this keyword
Use the this keyword to refer to the current object. In general, this refers to the calling object in a method. Use this as follows: this[.propertyName] Example 1. Suppose a function called validate validates an object's value property, given the object and the high and low values: function validate(obj, lowval, hival) { if ((obj.value < lowval) || (obj.value > hival)) alert("Invalid Value!") }
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov.htm (5 of 7) [30/08/2003 9:34:07 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov.htm

You could call validate in each form element's onChange event handler, using this to pass it the form element, as in the following example: <B>Enter a number between 18 and 99:</B> <INPUT TYPE = "text" NAME = "age" SIZE = 3 onChange="validate(this, 18, 99)"> Example 2. When combined with the form property, this can refer to the current object's parent form. In the following example, the form myForm contains a Text object and a button. When the user clicks the button, the value of the Text object is set to the form's name. The button's onClick event handler uses this.form to refer to the parent form, myForm. <FORM NAME="myForm"> Form name:<INPUT TYPE="text" NAME="text1" VALUE="Beluga"> <P> <INPUT NAME="button1" TYPE="button" VALUE="Show Form Name" onClick="this.form.text1.value=this.form.name"> </FORM>

for...in statement
The for...in statement iterates a specified variable over all the properties of an object. For each distinct property, JavaScript executes the specified statements. A for...in statement looks as follows: for (variable in object) { statements } Example. The following function takes as its argument an object and the object's name. It then iterates over all the object's properties and returns a string that lists the property names and their values. function dump_props(obj, obj_name) { var result = "" for (var i in obj) { result += obj_name + "." + i + " = " + obj[i] + "<BR>" } result += "<HR>" return result } For an object car with properties make and model, result would be: car.make = Ford car.model = Mustang

with statement
The with statement establishes the default object for a set of statements. Within the set of statements, any property references that do not specify an object are assumed to be for the default object. A with statement looks as follows:
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov.htm (6 of 7) [30/08/2003 9:34:07 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov.htm

with (object){ statements } Example. The following with statement specifies that the Math object is the default object. The statements following the with statement refer to the PI property and the cos and sin methods, without specifying an object. JavaScript assumes the Math object for these references. var a, x, y var r=10 with (Math) a x y }

{ = PI * r * r = r * cos(PI) = r * sin(PI/2)

Comments
Comments are author notations that explain what a script does. Comments are ignored by the interpreter. JavaScript supports Java-style comments:
q q

Comments on a single line are preceded by a double-slash (//). Comments that span multiple lines are preceded by /* and followed by */:

Example. The following example shows two comments: // This is a single-line comment. /* This is a multiple-line comment. It can be of any length, and you can put whatever you want here. */

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmtsov.htm (7 of 7) [30/08/2003 9:34:07 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm

Statements
avaScript statements consist of keywords used with the appropriate syntax. A single statement may span multiple lines. Multiple statements may occur on a single line if each statement is separated by a semi-colon. Syntax conventions: All keywords in syntax statements are in bold. Words in italics represent userdefined names or statements. Any portions enclosed in square brackets, [ ], are optional. {statements} indicates a block of statements, which can consist of a single statement or multiple statements delimited by a curly braces {}. The following statements are available in JavaScript:

break comment continue for for...in function if...else

new (operator) return this (operator) var while with

Note new and this are not statements, but are included in this section for convenience.

break
A statement that terminates the current while or for loop and transfers program control to the statement following the terminated loop.

Syntax
break

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm (1 of 14) [30/08/2003 9:34:08 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm

Implemented in
Navigator 2.0

Examples
The following function has a break statement that terminates the while loop when i is 3, and then returns the value 3 * x. function var i while if i++ } return i*x } testBreak(x) { = 0 (i < 6) { (i == 3) break

comment
Notations by the author to explain what a script does. Comments are ignored by the interpreter. JavaScript supports Java-style comments:
q q

Comments on a single line are preceded by a double-slash (//). Comments that span multiple lines are preceded by a /* and followed by a */.

Syntax
1. // comment text 2. /* multiple line comment text */

Implemented in
Navigator 2.0

Examples
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm (2 of 14) [30/08/2003 9:34:08 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm

// This is a single-line comment. /* This is a multiple-line comment. It can be of any length, and you can put whatever you want here. */

continue
A statement that terminates execution of the block of statements in a while or for loop, and continues execution of the loop with the next iteration. In contrast to the break statement, continue does not terminate the execution of the loop entirely: instead,
q q

In a while loop, it jumps back to the condition. In a for loop, it jumps to the update expression.

Syntax
continue

Implemented in
Navigator 2.0

Examples
The following example shows a while loop that has a continue statement that executes when the value of i is 3. Thus, n takes on the values 1, 3, 7, and 12. i = 0 n = 0 while (i < 5) { i++ if (i == 3) continue n += i }

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm (3 of 14) [30/08/2003 9:34:08 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm

for
A statement that creates a loop that consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a block of statements executed in the loop.

Syntax
for ([initial-expression;] [condition;] [increment-expression]) { statements }

Arguments
initial-expression is a statement or variable declaration. It is typically used to initialize a counter variable. This expression may optionally declare new variables with the var keyword. condition is evaluated on each pass through the loop. If this condition evaluates to true, the statements in statements are performed. This conditional test is optional. If omitted, the condition always evaluates to true. increment-expression is generally used to update or increment the counter variable. statements is a block of statements that are executed as long as condition evaluates to true. This can be a single statement or multiple statements. Although not required, it is good practice to indent these statements from the beginning of the for statement.

Implemented in
Navigator 2.0

Examples
The following for statement starts by declaring the variable i and initializing it to zero. It checks that i is less than nine, performs the two succeeding statements, and increments i by one after each pass through the loop. for (var i = 0; i < 9; i++) { n += i myfunc(n)
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm (4 of 14) [30/08/2003 9:34:08 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm

}

for...in
A statement that iterates a specified variable over all the properties of an object. For each distinct property, JavaScript executes the specified statements.

Syntax
for (variable in object) { statements }

Arguments
variable is the variable to iterate over every property. object is the object for which the properties are iterated. statements specifies the statements to execute for each property.

Implemented in
Navigator 2.0

Examples
The following function takes as its argument an object and the object's name. It then iterates over all the object's properties and returns a string that lists the property names and their values. function dump_props(obj, obj_name) { var result = "" for (var i in obj) { result += obj_name + "." + i + " = " + obj[i] + "<BR>" } result += "<HR>" return result }
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm (5 of 14) [30/08/2003 9:34:08 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm

function
A statement that declares a JavaScript function name with the specified parameters param. Acceptable parameters include strings, numbers, and objects. To return a value, the function must have a return statement that specifies the value to return. You cannot nest a function statement in another statement or in itself. All parameters are passed to functions, by value. In other words, the value is passed to the function, but if the function changes the value of the parameter, this change is not reflected globally or in the calling function. In addition to defining functions as described here, you can also define Function objects, as described in "Function".

Syntax
function name([param] [, param] [..., param]) { statements }

Arguments
name is the function name. param is the name of an argument to be passed to the function. A function can have up to 255 arguments.

Implemented in
Navigator 2.0

Examples
//This function returns the total dollar amount of sales, when //given the number of units sold of products a, b, and c. function calc_sales(units_a, units_b, units_c) { return units_a*79 + units_b*129 + units_c*699
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm (6 of 14) [30/08/2003 9:34:08 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm

}

if...else
A statement that executes a set of statements if a specified condition is true. If the condition is false, another set of statements can be executed.

Syntax
if (condition) { statements1 } [else { statements2}]

Arguments
condition can be any JavaScript expression that evaluates to true or false. Parentheses are required around the condition. If condition evaluates to true, the statements in statements1 are executed. statements1 and statements2 can be any JavaScript statements, including further nested if statements. Multiple statements must be enclosed in braces.

Implemented in
Navigator 2.0

Examples
if ( cipher_char == from_char ) { result = result + to_char x++ } else result = result + clear_char

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm (7 of 14) [30/08/2003 9:34:08 PM]

An object can have a property that is itself another object. this does not affect any other objects.paramN are the property values for the object..color = "black" adds a property color to car1. see "prototype". file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts. Date. and assigns it a value of "black". properties. These properties are parameters defined for the objectType function.paramN] ) Arguments objectName is the name of the new object instance.description="The day you were born" Syntax objectName = new objectType ( param1 [. and then assigns a value to the color property of the object car1. the statement car1. It must be a function that defines an object type.. However. you must add the property to the definition of the car object type. 2. create a function for the object type that specifies its name. rather than by just one instance of the object. Create an instance of the object with new. Function. Boolean. Car..htm (8 of 14) [30/08/2003 9:34:08 PM] .[. Creating a user-defined object type requires two steps: 1. You can add a property to a previously defined object type by using the prototype property. Number. or String.prototype.color="black" birthday. param1. See the examples below. To add the new property to all objects of the same type. You can always add a property to a previously defined object. This defines a property that is shared by all objects of the specified type.htm new An operator that lets you create an instance of a user-defined object type or of one of the built-in object types Array. To define an object type.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts. For more information. Math. The following code adds a color property to all objects of type car. Define the object type by writing a function..param2] . For example.color=null car1. and methods. objectType is the object type.

model. Suppose you want to create an object type for cars. and you want it to have properties for make. 33. kenscar = new car("Nissan". You want this type of object to be called car. and so on.htm (9 of 14) [30/08/2003 9:34:08 PM] . year) { this. Suppose you define an object called person as follows: function person(name. For example. 1993) This statement creates mycar and assigns it the specified values for its properties.model = model this. you would write the following function: function car(make.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts. and year. 39. 1992) Example 2: object property that is itself another object. sex) { this.sex = sex } And then instantiate two new person objects as follows: rand = new person("Rand McNally". age. To do this.make is the string "Eagle". "300ZX".make = make this. Then the value of mycar.year = year } Now you can create an object called mycar as follows: mycar = new car("Eagle".0 Examples Example 1: object type and object instance. "M") ken = new person("Ken Jones".age = age this.htm Implemented in Navigator 2.name = name this. model. "M") file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts. You can create any number of car objects by calls to new. mycar.year is the integer 1993. "Talon TSi".

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts. where x is a number. you then use the following: car1 = new car("Eagle".year = year.htm (10 of 14) [30/08/2003 9:34:08 PM] . } To instantiate the new objects. rand).owner.name return A statement that specifies the value to be returned by a function.htm Then you can rewrite the definition of car to include an owner property that takes a person object. year. this. To find out the name of the owner of car2. owner) { this. Syntax return expression Implemented in Navigator 2. as follows: function car(make. 1992. this. this.model = model.make = make. "Talon TSi".owner = owner. model.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts. the above statements pass the objects rand and ken as the parameters for the owners.0 Examples The following function returns the square of its argument. ken) Instead of passing a literal string or integer value when creating the new objects. "300ZX". 1993. x. you can access the following property: car2. car2 = new car("Nissan".

Syntax this[. using this to pass it the form element. lowval.value > hival)) alert("Invalid Value!") } You could call validate in each form element's onChange event handler. 18. given the object and the high and low values: function validate(obj.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.0 Examples Suppose a function called validate validates an object's value property.htm function square( x ) { return x * x } this A keyword that you can use to refer to the current object.value < lowval) || (obj.propertyName] Implemented in Navigator 2. in a method this refers to the calling object.htm (11 of 14) [30/08/2003 9:34:08 PM] . 99)"> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts. In general. as in the following example: <B>Enter a number between 18 and 99:</B> <INPUT TYPE = "text" NAME = "age" SIZE = 3 onChange="validate(this. hival) { if ((obj.

as long as the specified condition is true.. and it is necessary in functions if a global variable of the same name exists.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.0 Examples var num_hits = 0. Implemented in Navigator 2. you can declare a variable by simply assigning it a value. cust_no = 0 while A statement that creates a loop that evaluates an expression. Using var outside a function is optional.. Syntax while (condition) { file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts. Syntax var varname [= value] [. and if it is true. The scope of a variable is the current function or.htm (12 of 14) [30/08/2003 9:34:08 PM] .. However. it is good style to use var.htm var A statement that declares a variable. for variables declared outside a function. It can be any legal identifier. The loop then repeats. value is the initial value of the variable and can be any legal expression. varname [= value] ] Arguments varname is the variable name. optionally initializing it to a value. executes a block of statements. the current application.

the loop increments n and adds it to x. the statements in the succeeding block are performed. the condition n < 3 is no longer true.htm statements } Arguments condition is evaluated before each pass through the loop. x and n take on the following values: q q q After the first pass: n = 1 and x = 1 After the second pass: n = 2 and x = 3 After the third pass: n = 3 and x = 6 After completing the third pass. When condition evaluates to false. Therefore. it is good practice to indent these statements from the beginning of the while statement. Implemented in Navigator 2.0 Examples The following while loop iterates as long as n is less than three. Although not required. statements is a block of statements that are executed as long as the condition evaluates to true.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts. execution continues with the statement following statements. If this condition evaluates to true. n = 0 x = 0 while( n < 3 ) { n ++ x += n } Each iteration. so the loop terminates. with file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm (13 of 14) [30/08/2003 9:34:08 PM] .

statements is any block of statements. y var r=10 with (Math) { a = PI * r * r x = r * cos(PI) y = r * sin(PI/2) } file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts.htm (14 of 14) [30/08/2003 9:34:08 PM] . any property references that do not specify an object are assumed to be for the default object. without specifying an object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/stmts. Within the set of statements.0 Examples The following with statement specifies that the Math object is the default object. The statements following the with statement refer to the PI property and the cos and sin methods. x. The parentheses around object are required. Syntax with (object){ statements } Arguments object specifies the default object to use for the statements.htm A statement that establishes the default object for a set of statements. Implemented in Navigator 2. JavaScript assumes the Math object for these references. var a.

and double are converted to JavaScript numbers. Values passed from Java to JavaScript are converted as follows: q q q q q JSObject is converted to the original JavaScript object.htm (1 of 9) [30/08/2003 9:34:09 PM] . Values passed from JavaScript to Java are converted as follows: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages.JSObject netscape.javascript. Converting to a boolean will try to call the booleanValue method in the same way. float. Java arrays are wrapped with a JavaScript object that understands array.plugin applet API package has the following classes: q netscape.javascript applet API package has the following classes: q q netscape. int.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages.javascript and netscape.JSObject The public final class JSObject extends Object. A Java boolean is converted to a JavaScript boolean. char.javascript.plugin.javascript.JSObject JSObject allows Java to manipulate objects that are defined in JavaScript. java.Object | +----netscape.plugin. converting to a number will call the floatValue method if possible and fail otherwise.JSException The netscape. netscape. which can be used to access methods and fields of the Java object.Plugin The following sections describe these classes and list their constructors and methods. long.htm The Netscape packages iveConnect has two applet API packages: netscape.javascript. Converting this wrapper to a string will call the toString method on the original object. short.length and array[index]. Any other Java object is converted to a JavaScript wrapper. The netscape. Java byte.lang.

htm (2 of 9) [30/08/2003 9:34:09 PM] . this conversion happens automatically--you can pass in "int" argument and it works. Float.javascript.lang. Other objects are wrapped with a JSObject.getMember("name") (JSObject) window.htm q q q Objects that are wrappers around Java objects are unwrapped. This means that all JavaScript values show up as some kind of java. as shown in the following examples: (String) window. In order to make much use of them.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages.JSObject class has the following static methods: Method Description getWindow Gets a JSObject for the window containing the given applet file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages. you will have to cast them to the appropriate subclass of Object. and Boolean objects respectively. numbers. Methods and static methods The netscape.Object in Java. Strings.javascript.getMember("document") Note If you call a Java method from JavaScript. and booleans are converted to String.JSObject class has the following methods: Method call eval getMember getSlot Description Calls a JavaScript method Evaluates a JavaScript expression Retrieves a named member of a JavaScript object Retrieves an indexed member of a JavaScript object removeMember Removes a named member of a JavaScript object setMember setSlot toString Sets a named member of a JavaScript object Sets an indexed member of a JavaScript object Converts a JSObject to a string The netscape.

Retrieves a named member of a JavaScript object.htm The following sections show the declaration and usage of these methods. Retrieves an indexed member of a JavaScript object. call Method..name" in JavaScript. Object args[]) eval Method. Declaration public Object call(String methodName. Declaration public Object getSlot(int index) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages. args[1]. Calls a JavaScript method. Declaration public Object getMember(String name) getSlot Method. Equivalent to "this[index]" in JavaScript.methodName(args[0]. Equivalent to "this. Declaration public Object eval(String s) getMember Method. The expression is a string of JavaScript source code which will be evaluated in the context given by "this". .htm (3 of 9) [30/08/2003 9:34:09 PM] . Equivalent to "this. Evaluates a JavaScript expression.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages..)" in JavaScript.

htm (4 of 9) [30/08/2003 9:34:09 PM] . Declaration public void removeMember(String name) setMember Method. Object value) setSlot Method. Declaration public void setMember(String name. Declaration public static JSObject getWindow(Applet applet) removeMember Method.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages. Equivalent to "this[index] = value" in JavaScript. Declaration public void setSlot(int index. Object value) toString file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages. Sets an indexed member of a JavaScript object. Sets a named member of a JavaScript object.htm getWindow Static method.name = value" in JavaScript. Returns a JSObject for the window containing the given applet. Removes a named member of a JavaScript object. Equivalent to "this.

javascript.javascript. JSException Constructor. You specify whether the JSException has a detail message and other information. Constructs a JSException. You specify whether the JSException has a detail message and file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages. Constructors The netscape.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages.JSException JSException is an exception that is thrown when JavaScript code returns an error.javascript. java. The following sections show the declaration and usage of these constructors.lang. Overrides: toString in class Object Declaration public String toString() netscape.htm (5 of 9) [30/08/2003 9:34:09 PM] .lang.JSException class has the following constructors: Constructor Description JSException Constructs a JSException.htm Method.Throwable | +----java. Converts a JSObject to a String.Exception | +----netscape.JSException The public class JSException extends Exception.Object | +----java.lang.

tokenIndex is the index into the source string where the error occurred. if possible.plugin. Form 3 of the declaration constructs a JSException with a detail message and all the other information that usually comes with a JavaScript error. netscape. public JSException(String s. public JSException() 2. lineno is the line number if the file. Declaration 1. Description A detail message is a string that describes this particular exception. Form 2 of the declaration constructs a JSException with a detail message. int lineno.Plugin file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages. String filename. Each form constructs a JSException with different information: q q q Form 1 of the declaration constructs a JSException without a detail message.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages.htm other information. String source. filename is the URL of the file where the error occurred.htm (6 of 9) [30/08/2003 9:34:09 PM] . if possible. int tokenIndex) Arguments s is the detail message. public JSException(String s) 3. source is the string containing the JavaScript code being evaluated.

plugin.Object | +----netscape. Called when the plug-in is destroyed.plugin. You never need to call this method directly.Plugin class has the following methods: Method destroy getPeer Description Called when the plug-in is destroyed Returns the native NPP object--the plug-in instance that is the native part of a Java Plugin object getWindow Returns the JavaScript window on which the plug-in is embedded init isActive Called when the plug-in is initialized Determines whether the Java reflection of a plug-in still refers to an active plug-in The following sections show the declaration and usage of these constructors and methods. the plug-in will still be active. Plug-ins that need to have Java methods associated with them should subclass this class and add new (possibly native) methods to it. The netscape.Plugin This class represents the Java reflection of a plug-in.plugin.Plugin class has the following constructors: Constructor Description Plugin Constructs a Plugin. Constructors and methods The netscape.htm The public class Plugin extends Object.lang. This allows other Java entities (such as applets and JavaScript code) to manipulate the plug-in.htm (7 of 9) [30/08/2003 9:34:09 PM] . it is called when the plug-in is destroyed. destroy Method.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages. At the point this method is called. java. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages.

thisPlugin). but can be read from plug-in native methods by calling: NPP npp = (NPP)netscape_plugin_Plugin_getPeer(env.htm Declaration public void destroy() See also init getPeer Method. it is called when the plug-in is created. Declaration public JSObject getWindow() init Method. This field is set by the system. Declaration public void init() See also file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages. You never need to call this method directly.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages. Called when the plug-in is initialized. Returns the JavaScript window on which the plug-in is embedded. Returns the native NPP object--the plug-in instance that is the native part of a Java Plugin object. Declaration public int getPeer() getWindow Method method.htm (8 of 9) [30/08/2003 9:34:09 PM] .

Declaration public boolean isActive() Plugin Constructor. thereby causing the plug-in to no longer be active.htm (9 of 9) [30/08/2003 9:34:09 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages. Declaration public Plugin() file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/packages.htm destroy isActive Method. Constructs a Plugin. Plug-in instances are destroyed whenever the page containing the plug-in is left. Determines whether the Java reflection of a plug-in still refers to an active plug-in.

abs(number) Parameters number is any numeric expression or a property of an existing object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.0 Examples The following function returns the absolute value of the variable x: function getAbs(x) { return Math. event handlers. abs Method.htm Navigator JavaScript reference his chapter is an alphabetical reference of all objects. and "untaint". the "Tainted?" section indicates whether the property is tainted by default. properties. For each property. methods. Method of Math Implemented in Navigator 2. see "Using data tainting for security". Syntax Math.abs(x) } acos file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.htm (1 of 59) [30/08/2003 9:34:12 PM] . Returns the absolute value of a number. "taint". and functions. For information on tainting.

atan. Method of Math Implemented in Navigator 2. If the value of number is outside this range.htm (2 of 59) [30/08/2003 9:34:12 PM] . it returns zero because two is out of range.acos(number) Parameters number is a numeric expression between -1 and 1.htm Method. if you pass it the value two. it returns 3. sin. or a property of an existing object. atan2. Examples The following function returns the arc cosine of the variable x: function getAcos(x) { return Math.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. tan methods action Property.acos(x) } If you pass getAcos the value -1.0 Description The acos method returns a numeric value between zero and pi radians. cos. A string specifying a destination URL for form data that is submitted. Syntax Math.141592653589793. See also asin. it returns zero. Returns the arc cosine (in radians) of a number. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.

Property of Form object Implemented in Navigator 2. Each section of a URL contains different information. Form object alert Method. See the location object for a description of the URL components. target properties.htm Syntax formName. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Displays an Alert dialog box with a message and an OK button.action=urlName See also encoding. You can set the action property at any time.0 Tainted? Yes Description The action property is a reflection of the ACTION attribute of the <FORM> tag. Examples The following example sets the action property of the musicForm form to the value of the variable urlName: document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. method.action Parameters formName is either the name of a form or an element in the forms array.htm (3 of 59) [30/08/2003 9:34:12 PM] .musicForm.

You cannot specify a title for an alert dialog box.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. as shown in the following file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. the testValue function checks the name entered by a user in the Text object of a form to make sure that it is no more than eight characters in length.alert() is unnecessary. The message argument specifies a message that the dialog box contains.htm Syntax alert("message") Parameters message is any string or a property of an existing object. This example uses the alert method to prompt the user to enter a valid value. For example.htm (4 of 59) [30/08/2003 9:34:12 PM] .0 Description An alert dialog box looks as follows: Click for sample alert dialog box Use the alert method to display a message that does not require a user decision.length > 8) { alert("Please enter a name that is 8 characters or less") } } You can call the testValue function in the onBlur event handler of a form's Text object. windowReference. you do not need to specify a windowReference when you call it. See open (window object). Examples In the following example. Although alert is a method of the window object. function testValue(textElement) { if (textElement. but you can use the open method to create your own "alert" dialog. Method of window object Implemented in Navigator 2.

For example. If you express the color as a hexadecimal RGB triplet. This property is the JavaScript reflection of the ALINK attribute of the <BODY> tag.htm example: Name: <INPUT TYPE="text" NAME="userName" onBlur="testValue(userName. A string specifying the color of an active link (after mouse-button down. Syntax document. the hexadecimal RGB values for salmon are red=FA. and blue=72. prompt methods alinkColor Property. but before mouse-button up)." Examples The following example sets the color of active links using a string literal: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. You cannot set this property after the HTML source has been through layout.0 Tainted? No Description The alinkColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in "Color values".htm (5 of 59) [30/08/2003 9:34:12 PM] .alinkColor Property of document Implemented in Navigator 2. so the RGB triplet for salmon is "FA8072.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. you must use the format rrggbb.value)"> See also confirm. green=80.

Create the anchor with the anchor method. vlinkColor properties anchor method Method.htm (6 of 59) [30/08/2003 9:34:12 PM] . file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. fgColor. the text string represents the literal text that you want the user to see.0 Description Use the anchor method with the write or writeln methods to programmatically create and display an anchor in a document.alinkColor="00FFFF" See also bgColor. Creates an HTML anchor that is used as a hypertext target.htm document.alinkColor="aqua" The following example sets the color of active links to aqua using a hexadecimal triplet: document. Method of String Implemented in Navigator 2. linkColor. Syntax text. In the syntax. and then call write or writeln to display the anchor in a document. nameAttribute is any string or a property of an existing object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.anchor(nameAttribute) Parameters text is any string or a property of an existing object. The nameAttribute string represents the NAME attribute of the <A> tag.

writeln(myString. See the Link object for details. A link to the anchor uses this value for its HREF attribute.htm Anchors created with the anchor method become elements in the anchors array. HTML attributes HREF=locationOrURL is used only if the anchor is also a link.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. A place in a document that is the target of a hypertext link.document. See the Anchor object for information about the anchors array. It identifies a destination anchor or URL for the link.htm (7 of 59) [30/08/2003 9:34:12 PM] . use standard HTML syntax: <A [HREF=locationOrURL] NAME="anchorName" [TARGET="windowName"]> anchorText </A> You can also define an anchor using the anchor method. Examples The following example opens the msgWindow window and creates an anchor for the Table of Contents: var myString="Table of Contents" msgWindow.anchor("contents_anchor")) The previous example produces the same output as the following HTML: <A NAME="contents_anchor">Table of Contents</A> See also link method Anchor object Object. NAME="anchorName" specifies a name for the anchor. You can use this name when indexing the anchors array. HTML syntax To define an anchor.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. if a document contains three named anchors. and document. the statement document. Elements in the anchors array are read-only.anchors[2]. use the length property: document. anchorText specifies the text or HTML source to display at the anchor.htm (8 of 59) [30/08/2003 9:34:12 PM] . To obtain the number of anchors in a document. See the Link object for details.anchors[1]. This array contains an entry for each <A> tag containing a NAME attribute in a document in source order. See the example below.anchors[0]="anchor1" has no effect. you can use the anchors array and its length property to validate an anchor name before using it in operations such as setting location. the object has entries in both the anchors and links arrays. Properties The anchors object has no properties. The anchors array has the following properties: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Property of document Implemented in Navigator 2.hash. document.length.anchors. If a document names anchors in a systematic way using natural numbers.0 Description If an Anchor object is also a Link object.anchors[0].anchors. To use the anchors array: 1. document. these anchors are reflected as document. For example. For example. document.length index is an integer representing an anchor in a document or the name of an Anchor object as specified by the NAME attribute.anchors[index] 2. It specifies the window that the link is loaded into. The anchors array You can reference the Anchor objects in your code by using the anchors array.htm TARGET="windowName" is used only if the anchor is also a link.

" "1.length-1). 1.document.html#javascript_intro">Introduction</A> Example 2: anchors array.anchors.. link1." "2.width=250.hash in the second window to a specific anchor."secondLinkWindow". Examples Example 1: An anchor. a link in another file could define a jump to the anchor as follows: <A HREF="intro. contains the following code: <HTML> <HEAD> <TITLE>Links and Anchors: Window 1</TITLE> </HEAD> <BODY> <SCRIPT> window2=open("link2.htm (9 of 59) [30/08/2003 9:34:12 PM] . (document.length > num) window2.location. 2." (The anchor names in the document are therefore 0. The following example opens two windows. "scrollbars=yes. height=400") function linkToWindow(num) { if (window2.anchors. .hash=num else alert("Anchor does not exist!") file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. The first window contains a series of buttons that set location. The following example defines an anchor for the text "Welcome to JavaScript": <A NAME="javascript_intro"><H2>Welcome to JavaScript</H2></A> If the preceding anchor is in a file called intro. The second window defines four anchors named "0.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c." and "3.html".htm Property Description length Reflects the number of named anchors in the document Methods q q q eval toString valueOf Event handlers None. which defines the first window and its buttons.) When a button is pressed in the first window..html. the onClick event handler verifies that the anchor exists before setting window2.hash to the specified anchor name.html.location.

which contains the anchors.html.value)"> <INPUT TYPE="button" VALUE="4" NAME="link0_button" onClick="linkToWindow(this.htm } </SCRIPT> <B>Links and Anchors</B> <FORM> <P>Click a button to display that anchor in window #2 <P><INPUT TYPE="button" VALUE="0" NAME="link0_button" onClick="linkToWindow(this.value)"> </FORM> </BODY> </HTML> link2.value)"> <INPUT TYPE="button" VALUE="3" NAME="link0_button" onClick="linkToWindow(this. contains the following code: <HTML> <HEAD> <TITLE>Links and Anchors: Window 2</TITLE> </HEAD> <BODY> <A NAME="0"><B>Some numbers</B> (Anchor 0)</A> <UL><LI>one <LI>two <LI>three <LI>four</UL> <P><A NAME="1"><B>Some colors</B> (Anchor 1)</A> <UL><LI>red <LI>orange <LI>yellow <LI>green</UL> <P><A NAME="2"><B>Some music types</B> (Anchor 2)</A> <UL><LI>R&B <LI>Jazz <LI>Soul <LI>Reggae <LI>Rock</UL> <P><A NAME="3"><B>Some countries</B> (Anchor 3)</A> <UL><LI>Afghanistan <LI>Brazil <LI>Canada <LI>Finland <LI>India</UL> </BODY> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.value)"> <INPUT TYPE="button" VALUE="2" NAME="link0_button" onClick="linkToWindow(this.value)"> <INPUT TYPE="button" VALUE="1" NAME="link0_button" onClick="linkToWindow(this.htm (10 of 59) [30/08/2003 9:34:12 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.

anchor method anchors Property.0 Tainted? No Description appCodeName is a read-only property. Syntax navigator.htm (11 of 59) [30/08/2003 9:34:12 PM] . See the Anchor object for information.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. An array of objects corresponding to named anchors in source order.htm </HTML> See also Link object. Tainted? No appCodeName Property. A string specifying the code name of the browser. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.appCodeName Property of navigator Implemented in Navigator 2.

htm (12 of 59) [30/08/2003 9:34:12 PM] . userAgent properties Applet Object. This file name must end in a file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. this displays the following: The value of navigator.0 and 3. javaEnabled. HTML syntax To include a Java applet in a web page. Includes a Java applet in a web page. appVersion.appCodeName) For Navigator 2. use standard HTML syntax: <APPLET CODE=classFileName HEIGHT=height WIDTH=width MAYSCRIPT [NAME=appletName] [CODEBASE=classFileDirectory] [ALT=alternateText] [ALIGN="left"|"right"| "top"|"absmiddle"|"absbottom"| "texttop"|"middle"|"baseline"|"bottom"] [HSPACE=spaceInPixels] [VSPACE=spaceInPixels]> [<PARAM NAME=parameterName VALUE=parameterValue>] [ .appCodeName is " + navigator.appCodeName is Mozilla See also appName.htm Examples The following example displays the value of the appCodeName property: document.0.. <PARAM>] </APPLET> HTML attributes CODE=classFileName specifies the file name of the applet that you want to load.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.write("The value of navigator..

htm (13 of 59) [30/08/2003 9:34:12 PM] . You can use this name when indexing the applets array. the applet will not work with JavaScript.class extension. within the browser window. <PARAM> defines a parameter for the applet. VALUE=parameterValue> specifies a value for the parameter. Property of document Implemented in file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. within the browser window. in pixels.htm . NAME=appletName specifies the name of the applet. HSPACE=spaceInPixels specifies a horizontal margin for the applet. VSPACE=spaceInPixels specifies a vertical margin for the applet.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.class file. HEIGHT=height specifies the height of the applet in pixels within the browser window. in pixels. NAME=parameterName specifies the name of the parameter. Use this attribute to prevent an applet from accessing JavaScript on a page without your knowledge. Syntax To use an applet object: document. MAYSCRIPT permits the applet to access JavaScript. if it is different from the directory that contains the HTML page. ALT=alternateText specifies text to display for browsers that do not support the <APPLET> tag. CODEBASE=classFileDirectory specifies directory of the .applets[index] Parameters index is an integer representing an applet in a document or the name of an Applet object as specified by the NAME attribute. If omitted. ALIGN=alignment specifies the alignment of the applet on the HTML page. WIDTH=width specifies the width of the applet in pixels within the browser window.

htm Navigator 3. "LiveConnect. document. and document. document.applets[1]. To use the applets array: 1. specify the following: <APPLET CODE="musicPicker." The applets array You can reference the applets in your code by using the applets array. The applets array has the following properties: Property Description length Reflects the number of <APPLET> tags in the document Methods file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. This array contains an entry for each Applet object (<APPLET> tag) in a document in source order. document. For example. to allow the musicPicker.class" has no effect.applets.class applet access to JavaScript on your page.applets[0]. To obtain the number of applets in a document.applets[0]="myApplet. these applets are reflected as document. if a document contains three applets.class" WIDTH=200 HEIGHT=35 NAME="musicApp" MAYSCRIPT> Accessing JavaScript when the MAYSCRIPT attribute is not specified results in an exception.length index is an integer representing an applet in a document or the name of an Applet object as specified by the NAME attribute. use the length property: document. For example.applets[index] 2.applets[2].0 Description The author of an HTML page must permit an applet to access JavaScript by specifying the MAYSCRIPT attribute of the <APPLET> tag. For example.length. Properties All public properties of the applet are available for JavaScript access to the Applet object. the statement document. For more information on using applets. Elements in the applets array are read-only.htm (14 of 59) [30/08/2003 9:34:12 PM] .applets. see Chapter 4. This prevents an applet from accessing JavaScript on a page without the knowledge of the page author.

Chapter 4.class" WIDTH=200 HEIGHT=35 NAME="musicApp" MAYSCRIPT> </APPLET> For more examples. Syntax navigator. Examples The following code launches an applet called "musicApp": <APPLET CODE="musicSelect. see Chapter 4. A string specifying the name of the browser.htm q q q q All public methods of the applet eval toString valueOf Event handlers None.appName Property of navigator file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. An array reflecting all the applets in a document in source order. Plugin objects. "LiveConnect.htm (15 of 59) [30/08/2003 9:34:12 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. appName Property. "LiveConnect" applets Property." See also MimeType. See the Applet object for information.

appName is Netscape See also appCodeName. Examples The following example displays the value of the appName property: document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.appName is " + navigator.0 and 3. this displays the following: The value of navigator.htm Implemented in Navigator 2.appVersion Property of navigator Implemented in file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. appVersion.write("The value of navigator.appName) For Navigator 2. javaEnabled.0 Tainted? No Description appName is a read-only property.0. userAgent properties appVersion Property. Syntax navigator. A string specifying version information for the Navigator.htm (16 of 59) [30/08/2003 9:34:12 PM] .

release.appVersion is " + navigator.0 on Windows 95. this displays the following: The value of navigator. I) Example 2. this displays the following: The value of navigator. For example. The domestic release has a stronger encryption feature than the international release. beta 4.appVersion is 3.appVersion) For Navigator 2. which is the newline character for Unix and Macintosh.0b4" specifies Navigator 2. Because the newline character varies from platform to platform. the example tests the appVersion property to determine whether the user is running Windows (appVersion contains "Win" for all versions of Windows). "Win16" specifies a 16-bit version of Windows such as Windows 3. The following example displays version information for the Navigator: document. If the user is running Windows. country is either "I" for the international release. appVersion is a read-only property.0.write("The value of navigator.0 (Win95. the newline character is set to \r\n.htm Navigator 2. Examples Example 1.appVersion is 2. <SCRIPT> var newline=null function populate(textareaObject){ file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.0 Tainted? No Description The appVersion property specifies version information in the following format: releaseNumber (platform. I) For Navigator 3. For example. The following example populates a Textarea object with newline characters separating each line.11.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. or "U" for the domestic U.htm (17 of 59) [30/08/2003 9:34:12 PM] .0 on Windows NT. it's set to \n. country) The values contained in this format are the following: q q q releaseNumber is the version number of the Navigator. otherwise. platform is the platform upon which the Navigator is running.S.0 (WinNT. "2.

testLines)"> </TEXTAREA> </FORM> See also appCodeName. functionName. When the user clicks the area. the area's hypertext reference is loaded into its target window.form1. For information on Area objects.value="line 1" + newline + "line 2" + newline + "line 3" } </SCRIPT> <FORM NAME="form1"> <BR><TEXTAREA NAME="testLines" ROWS=8 COLS=55></TEXTAREA> <P><INPUT TYPE="button" VALUE="Populate the Textarea object" onClick="populate(document. Area objects are a type of Link object. appName. Defines an area of an image as an image map.htm if (navigator. Syntax To use the arguments array: 1. index is an integer representing an element of a function or the name of a function as specified in the function file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.htm (18 of 59) [30/08/2003 9:34:12 PM] . An array corresponding to elements of a function. arguments array Property.length Parameters functionName is the name of a function you have created or the name of a variable or a property of an existing object that has been assigned a Function object using new. userAgent properties Area Object.appVersion. see Link object. functionName.arguments[index] 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.arguments.lastIndexOf('Win') != -1) newline="\r\n" else newline="\n" textareaObject.

The arguments array is available only within a function declaration. Properties The arguments array has the following properties: Property Description length Reflects the number of arguments to the function Examples This example defines a function that creates HTML lists. so you must refer to functions and Function objects by name.arguments[i]) document.0 Tainted? No Description You can call a function with more arguments than it is formally declared to accept by using the arguments array. Property of Function object. This technique is useful if a function can be passed a variable number of arguments. i++) { document.htm (19 of 59) [30/08/2003 9:34:12 PM] . The function is defined as follows: function list(type) { document.write("<LI>" + list. any user-defined function (see See "Defining and calling functions") Implemented in Navigator 2.htm declaration.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.write("<" + type + "L>") for (var i=1. The this keyword does not refer to the currently executing function. and then treat each argument by using the arguments array. Attempting to access the arguments array outside a function declaration results in an error. even within the function body.arguments. The only formal argument for the function is a string that is "U" if the list is to be unordered (bulleted). i<list.write("</" + type + "L>") file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.length. You can use arguments. or "O" if the list is to be ordered (numbered).length to determine the number of arguments passed to the function.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. "One". and it displays each argument as an item in the type of list indicated. "Three") results in this output: <UL> <LI>One <LI>Two <LI>Three </UL> See also caller arguments property Property. See the arguments array for information.. Lets you create arrays and work with them..htm } } You can pass any number of arguments to this function. For example. An array of elements in a function.. element1. arrayObjectName = new Array([arrayLength]) 2. elementn]) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Tainted? No Array Object. arrayObjectName = new Array([element0. "Two". Syntax To create an Array object: 1. the following call to the function list("U".htm (20 of 59) [30/08/2003 9:34:12 PM] . .

arrayObjectName. propertyName is one of the properties listed below. elementn is a list of values for the array's elements. When this form is specified. The following code creates an array of 25 elements. The following code creates an array of length zero. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. then assigns a value to element 99. This changes the length of the array to 100. arrayLength is the initial length of the array.propertyName 2. Implemented in Navigator 3.0 Description The Array object is a built-in JavaScript object. all of its elements are initially null. arrayObjectName is either the name of an existing Array object or a property of an existing object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Property of None.htm To use Array objects: 1. arrayObjectName. and the array's length property is set to the number of arguments. The following code creates an array of five elements: billingMethod = new Array(5) When you create an array.htm (21 of 59) [30/08/2003 9:34:12 PM] . You can specify an initial length when you create the array. then assigns values to the first three elements: musicTypes = new Array(25) musicTypes[0] = "R&B" musicTypes[1] = "Blues" musicTypes[2] = "Jazz" An array's length increases if you assign a value to an element higher than the current length of the array. You can access this value using the length property. When using Array properties and methods.methodName(parameters) Parameters arrayObjectName is either the name of a new object or a property of an existing object. methodName is one of the methods listed below. the array is initalized with the specified values as its elements.

msgArray. with a length of 0."Rain". Methods The Array object has the following methods: q q q eval join reverse q q q sort toString valueOf Event handlers None."Fire") You can then refer to the first element of the array as myArray[0] or myArray["Wind"]. myVar. 3. Properties The Array object has the following properties: Property Description length Reflects the number of elements in an array prototype Lets you add a properties to an Array object.htm colors = new Array() colors[99] = "midnightblue" You can construct a dense array of two or more elements starting with index 0 if you define initial values for all elements.forms[0].file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. In Navigator 3. then assigns values to msgArray[0] and msgArray[99]. For example. for example document. you must index arrays by their ordinal number. you can index arrays by either their ordinal number or their name (if defined). suppose you define the following array: myArray = new Array("Wind".14159) In Navigator 2.htm (22 of 59) [30/08/2003 9:34:12 PM] .0. msgArray = new Array() file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. A dense array is one in which each element has a value. changing the length of the array to 100. Examples Example 1. The following code creates a dense array with three elements: myArray = new Array("Hello".0. The following example creates an array.

Example 2: Two-dimensional array."<p>") } This example displays the following results: Multidimensional array test Row 0:[0. a = new Array(4) for (i=0. i < 4.2][3.") See also the examples for the onError event handler.0][2.write("The length is 100.1][3. document.0][1.1][2. j < 4.write(str."+j+"]" } } for (i=0.2][1. i++) { a[i] = new Array(4) for (j=0. j++) { a[i][j] = "["+i+".2][2.3] Row 3:[3. j < 4. because defined msgArray [99] element.1][0.htm msgArray [0] = "Hello" msgArray [99] = "world" if (msgArray . j++) { str += a[i][j] } document. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.length == 100) // This is true.3] Row 2:[2. Returns the arc sine (in radians) of a number.1][1. The following code creates a two-dimensional array and displays the results. i < 4.3] Row 1:[1.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.0][3.0][0.3] See also Image object asin Method.2][0. i++) { str = "Row "+i+":" for (j=0.htm (23 of 59) [30/08/2003 9:34:12 PM] .

cos. it returns zero because two is out of range. it returns zero.htm Syntax Math. atan2.0 Description The asin method returns a numeric value between -pi/2 and pi/2 radians.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. tan methods atan Method. Returns the arc tangent (in radians) of a number. atan.asin(number) Parameters number is a numeric expression between -1 and 1. See also acos. sin. if you pass it the value two. it returns 1. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. or a property of an existing object.htm (24 of 59) [30/08/2003 9:34:12 PM] .asin(x) } If you pass getAsin the value one.570796326794897 (pi/2). Method of Math Implemented in Navigator 2. Examples The following function returns the arc sine of the variable x: function getAsin(x) { return Math. If the value of number is outside this range.

cos. it returns 0. asin. if you pass it the value .0 Description The atan method returns a numeric value between -pi/2 and pi/2 radians. Returns the angle in radians from the X axis to a point.4636476090008061.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.7853981633974483. See also acos.5.atan(number) Parameters number is either a numeric expression or a property of an existing object. representing the tangent of an angle. Method of Math Implemented in Navigator 2. Syntax file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.htm (25 of 59) [30/08/2003 9:34:12 PM] . it returns 0.atan(x) } If you pass getAtan the value 1. tan methods atan2 Method. atan2. Examples The following function returns the arc tangent of the variable x: function getAtan(x) { return Math.htm Syntax Math. sin.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.0 Description The atan2 method returns a numeric value between 0 and 2pi representing the angle theta of an (x.15). and the point (x.y).y) { return Math. asin. tan methods back Method.atan2(x.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Loads the previous URL in the history list. it returns 0. atan2 is passed separate x and y arguments.y) Parameters x is either a numeric expression or a property of an existing object.htm (26 of 59) [30/08/2003 9:34:12 PM] . representing the cartesian y-coordinate. This is the counter-clockwise angle. measured in radians. between the positive X axis. it returns 1.htm Math. and atan is passed the ratio of those two arguments.y) point. y is either a numeric expression or a property of an existing object.atan2(x.90). cos. See also acos. atan. Examples The following function returns the angle of the polar coordinate: function getAtan2(x.y) } If you pass getAtan2 the values (90.16514867741462683.4056476493802699. representing the cartesian x-coordinate. if you pass it the values (15. sin. Method of Math Implemented in Navigator 2.

htm (27 of 59) [30/08/2003 9:34:12 PM] . A string specifying the color of the document background.0 Description This method performs the same action as a user choosing the Back button in the Navigator. Syntax document.bgColor Property of file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.htm Syntax history. The back method is the same as history.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.back()"> <P><INPUT TYPE="button" VALUE="> Forward" onClick="history. Examples The following custom buttons perform the same operations as the Navigator Back and Forward buttons: <P><INPUT TYPE="button" VALUE="< Back" onClick="history.go(-1).forward()"> See also forward. go methods bgColor Property.back() Method of history object Implemented in Navigator 2.

which is displayed by choosing General Preferences from the Options menu. you must use the format rrggbb.bgColor="00FFFF" See also alinkColor. For example.htm document Implemented in Navigator 2. The default value of this property is set by the user on the Colors tab of the Preferences dialog box.0 Tainted? No Description The bgColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in "Color values".htm (28 of 59) [30/08/2003 9:34:12 PM] . This property is the JavaScript reflection of the BGCOLOR attribute of the <BODY> tag.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. If you express the color as a hexadecimal RGB triplet. the hexadecimal RGB values for salmon are red=FA. linkColor." Examples The following example sets the color of the document background to aqua using a string literal: document. vlinkColor properties big Method. fgColor. Causes a string to be displayed in a big font as if it were in a <BIG> tag. Syntax file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. so the RGB triplet for salmon is "FA8072.bgColor="aqua" The following example sets the color of the document background to aqua using a hexadecimal triplet: document. green=80. and blue=72. You can set the bgColor property at any time.

htm (29 of 59) [30/08/2003 9:34:12 PM] .htm stringName. small methods blink Method.big()) document. world</SMALL> <P><BIG>Hello.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Examples The following example uses string methods to change the size of a string: var worldString="Hello. Causes a string to blink as if it were in a <BLINK> tag.big() Parameters stringName is any string or a property of an existing object. world" document.small()) document.fontsize(7)) The previous example produces the same output as the following HTML: <SMALL>Hello. world</FONTSIZE> See also fontsize.write("<P>" + worldString. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.0 Description Use the big method with the write or writeln methods to format and display a string in a document. world</BIG> <P><FONTSIZE=7>Hello.write(worldString.write("<P>" + worldString. Method of String Implemented in Navigator 2.

strike methods blur file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.blink()) document.italics()) document.strike()) The previous example produces the same output as the following HTML: <BLINK>Hello. world</STRIKE> See also bold.write(worldString. world</BLINK> <P><B>Hello.blink() Parameters stringName is any string or a property of an existing object.0 Description Use the blink method with the write or writeln methods to format and display a string in a document.write("<P>" + worldString.write("<P>" + worldString.htm (30 of 59) [30/08/2003 9:34:12 PM] . italics.write("<P>" + worldString.bold()) document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. world" document. Method of String Implemented in Navigator 2.htm Syntax stringName. world</B> <P><I>Hello. world</I> <P><STRIKE>Hello. Examples The following example uses string methods to change the formatting of a string: var worldString="Hello.

htm Method.blur() Parameters fileUploadName is either the value of the NAME attribute of a FileUpload object or an element in the elements array. Removing focus from a window sends the window to the background in most windowing systems. windowReference is a valid way of referring to a window. passwordName is either the value of the NAME attribute of a Password object or an element in the elements array. 4.htm (31 of 59) [30/08/2003 9:34:12 PM] . Reset object object. 6. Select object. Method of Button object. textName is either the value of the NAME attribute of a Text object or an element in the elements array. Removes focus from the specified object. FileUpload object.0 Navigator 3.blur() passwordName. Submit and window Description Use the blur method to remove focus from a specific form element. Textarea object. Submit object. 5.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Checkbox object. Password object.blur() frameReference.blur() selectName.blur() textareaName. frameReference is a valid way of referring to a frame.0: method of Button. window. FileUpload. window object Implemented in q q Navigator 2. Radio. or frame. Text object. Syntax 1.blur() textName. as described in the window object. fileUploadName. textareaName is either the value of the NAME attribute of a Textarea object or an element in the elements array. Radio object. Checkbox. Frame. 2. Reset. 3. as described in the Frame object. 7.blur() windowReference. selectName is either the value of the NAME attribute of a Select object or an element in the elements array. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Frame object.

Syntax stringName.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Examples The following example uses string methods to change the formatting of a string: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.0 Description Use the bold method with the write or writeln methods to format and display a string in a document.htm (32 of 59) [30/08/2003 9:34:12 PM] . select method bold Method. Method of String Implemented in Navigator 2. Causes a string to be displayed as bold as if it were in a <B> tag.bold() Parameters stringName is any string or a property of an existing object.htm Examples The following example removes focus from the password element userPass: userPass.blur() This example assumes that the password is defined as <INPUT TYPE="password" NAME="userPass"> See also focus method.

world</BLINK> <P><B>Hello.strike()) The previous example produces the same output as the following HTML: <BLINK>Hello. world</STRIKE> See also blink. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.blink()) document.italics()) document. it the object has an initial value of false.htm var worldString="Hello. world</B> <P><I>Hello. or the empty string "".htm (33 of 59) [30/08/2003 9:34:12 PM] . The Boolean object is an object wrapper for a boolean value. including the string "false" create an object with an initial value of true. If value is omitted or is 0. Syntax To create a Boolean object: booleanObjectName = new Boolean(value) To use a Boolean object: booleanObjectName. if necessary. All other values.bold()) document. value is the initial value of the Boolean object. booleanObjectName is either the name of an existing Boolean object or a property of an existing object.write("<P>" + worldString.write("<P>" + worldString. strike methods Boolean Object. italics.write("<P>" + worldString. Lets you work with Boolean values. propertyName is one of the properties listed below. world</I> <P><STRIKE>Hello. world" document. The value is converted to a boolean value.propertyName Parameters booleanObjectName is either the name of a new object or a property of an existing object. false.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. When using Boolean properties.write(worldString. null.

htm (34 of 59) [30/08/2003 9:34:12 PM] . Use a Boolean object when you need to convert a non-boolean value to a boolean value. You can use the Boolean object any place JavaScript expects a primitive boolean value.htm Property of None Implemented in Navigator 3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Properties The Boolean object has the following properties: Property Description prototype Lets you add a properties to a Boolean object.0 Description The Boolean object is a built-in JavaScript object. JavaScript returns the primitive value of the Boolean object by automatically invoking the valueOf method. Examples The following examples create Boolean objects with an initial value of false: bNoParam = new Boolean() bZero = new Boolean(0) bNull = new Boolean(null) bEmptyString = new Boolean("") bfalse = new Boolean(false) The following examples create Boolean objects with an initial value of true: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Methods q q q eval toString valueOf Event handlers None.

of an image border.border Parameters imageName is either the name of an Image object or an element in the images array. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Examples The following function displays the value of an image's border property if the value is not zero. Syntax imageName.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.0 Tainted? No Description The border property reflects the BORDER attribute of the <IMG> tag.htm (35 of 59) [30/08/2003 9:34:12 PM] .htm btrue = new Boolean(true) btrueString = new Boolean("true") bfalseString = new Boolean("false") bSuLin = new Boolean("Su Lin") border Property. For images created with the Image() constructor. A string specifying the width. border is a read-only property. Property of Image Implemented in Navigator 3. in pixels. the value of the border property is 0.

propertyName buttonName. VALUE="buttonText" specifies the label to display on the button face. use standard HTML syntax with the addition of JavaScript event handlers: <INPUT TYPE="button" NAME="buttonName" VALUE="buttonText" [onBlur="handlerText"] [onClick="handlerText"] [onFocus="handlerText"]> HTML attributes NAME="buttonName" specifies the name of the Button object. HTML syntax To define a button. buttonName.htm (36 of 59) [30/08/2003 9:34:12 PM] . You can access this value using the value property. vspace. and you can use this name when indexing the elements array. Syntax To use a Button object's properties and methods: 1.elements[index]. A pushbutton on an HTML form.elements[index].htm function checkBorder(theImage) { if (theImage. You can access this value using the name property.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.methodName(parameters) formName. 2.methodName(parameters) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. 4. 3.border) } See also height. width properties Button Object.border==0) { alert('The image has no border!') } else alert('The image's border is ' + theImage. hspace.propertyName formName.

htm Parameters buttonName is the value of the NAME attribute of a Button object. The Button object is a custom button that you can use to perform an action you define. added blur and focus methods Description A Button object on a form looks as follows: Click me A Button object is a form element and must be defined within a <FORM> tag.htm (37 of 59) [30/08/2003 9:34:12 PM] .0: added type property.0 Navigator 3. added onBlur and onFocus event handlers. Property of Form object Implemented in q q Navigator 2. index is an integer representing a Button object on a form or the name of a Button object as specified by the NAME attribute. methodName is one of the methods listed below. The button executes the script specified by its onClick event handler. propertyName is one of the properties listed below. formName is either the value of the NAME attribute of a Form object or an element in the forms array. Properties The Button object has the following properties: Property name type Description Reflects the NAME attribute Reflects the TYPE attribute form property Specifies the form containing the Button object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.

Reset object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.htm (38 of 59) [30/08/2003 9:34:12 PM] . Syntax functionName. Submit object caller Property. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Returns the name of the function that invoked the currently executing function. When the button is clicked.form)"> See also Form object.caller Parameters functionName is the name of a function you have created or the name of a variable or a property of an existing object that has been assigned a Function object using new.htm value Reflects the VALUE attribute Methods The Button object has the following methods: q q q blur click eval q q q focus toString valueOf Event handlers q q q onBlur onClick onFocus Examples The following example creates a button named calcButton. The text "Calculate" is displayed on the face of the button. the function calcFunction is called. <INPUT TYPE="button" VALUE="Calculate" NAME="calcButton" onClick="calcFunction(this.

and that they will not call the called function again unconditionally (which would result in infinite recursion). function myFunc() { if (myFunc.caller == null) { alert("The function was called from the top!") } else alert("This function's caller was " + myFunc. you get the result of functionName. so q q If you use it in a string context. provided it knows that all of its callers have the same form and fit. You can also call the calling function. Examples The following code checks the value of a function's caller property.htm Property of Function object. any user-defined function (see See "Defining and calling functions") Implemented in Navigator 2.toString()--the decompiled canonical source form of the function.caller) } See also arguments array file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. If the currently executing function was invoked by the top level of a JavaScript program. The caller property is a reference to the calling function.0 Tainted? No Description The caller property is available only within the body of a function. The this keyword does not refer to the currently executing function.htm (39 of 59) [30/08/2003 9:34:12 PM] . a called function can call its caller without knowing the name of the particular caller. Thus. the value of caller is null. If used outside a function declaration. even within the function body. if you know what arguments it might want. so you must refer to functions and Function objects by name. the caller property is null.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.

ceil(number) Parameters number is any numeric expression or a property of an existing object.95. it returns -45. See also floor method charAt Method. Method of Math Implemented in Navigator 2.htm (40 of 59) [30/08/2003 9:34:12 PM] .95. Syntax Math. if you pass it the value -45. Returns the least integer greater than or equal to a number. it returns 46.htm ceil Method. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Returns the character at the specified index.0 Examples The following function returns the ceil value of the variable x: function getCeil(x) { return Math.ceil(x) } If you pass getCeil the value 45.

charAt(index) Parameters stringName is any string or a property of an existing object.1.htm Syntax stringName.write("The character at document. A checkbox is a toggle switch that lets the user set a value on or off. The index of the first character is zero. A checkbox on an HTML form.write("The character at index index index index index 0 1 2 3 4 is is is is is " " " " " + + + + + anyString.write("The character at document.0 Description Characters in a string are indexed from left to right. index is any integer from zero to stringName.1. split methods Checkbox Object.charAt(0)) anyString.charAt(4)) See also indexOf.length . and the index of the last character is stringName.charAt(1)) anyString. Examples The following example displays characters at different locations in the string "Brave new world": var anyString="Brave new world" document.write("The character at document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. lastIndexOf.htm (41 of 59) [30/08/2003 9:34:12 PM] .charAt(2)) anyString. JavaScript returns an empty string.write("The character at document. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. or a property of an existing object. Method of String Implemented in Navigator 2.charAt(3)) anyString. If the index you supply is out of range.length .

This defaults to "on.propertyName formName.htm HTML syntax To define a checkbox.htm (42 of 59) [30/08/2003 9:34:12 PM] . formName is either the value of the NAME attribute of a Form object or an element in the forms array. use standard HTML syntax with the addition of JavaScript event handlers: <INPUT TYPE="checkbox" NAME="checkboxName" VALUE="checkboxValue" [CHECKED] [onBlur="handlerText"] [onClick="handlerText"] [onFocus="handlerText"]> textToDisplay HTML attributes NAME="checkboxName" specifies the name of the Checkbox object. You can access this value using the defaultChecked property.elements[index]." You can access this value using the value property. 2. Syntax To use a Checkbox object's properties and methods: 1. and you can use this name when indexing the elements array. 3. index is an integer representing a Checkbox object on a form or the name of a Checkbox object as specified by the NAME attribute. CHECKED specifies that the checkbox is displayed as checked. VALUE="checkboxValue" specifies a value that is returned to the server when the checkbox is selected and the form is submitted. You can access this value using the name property. 4.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.elements[index]. textToDisplay specifies the label to display beside the checkbox. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.propertyName checkboxName.methodName(parameters) formName.methodName(parameters) Parameters checkboxName is the value of the NAME attribute of a Checkbox object. checkboxName.

form property name type value Specifies the form containing the Checkbox object Reflects the NAME attribute Reflects the TYPE attribute Reflects the VALUE attribute Methods The Checkbox object has the following methods: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Property of Form object Implemented in q q Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.htm propertyName is one of the properties listed below. Use the checked property to specify whether the checkbox is currently checked. added blur and focus methods Description A Checkbox object on a form looks as follows: Overnight delivery A Checkbox object is a form element and must be defined within a <FORM> tag. Lets you programmatically check a checkbox defaultChecked Boolean property that reflects the CHECKED attribute: true if checkbox is checked by default. Use the defaultChecked property to specify whether the checkbox is checked when the form is loaded or reset.htm (43 of 59) [30/08/2003 9:34:12 PM] .0 Navigator 3. false otherwise. Properties The Checkbox object has the following properties: Property checked Description Boolean property that reflects the current state of the checkbox: true for checked or false for unchecked. added onBlur and onFocus event handlers. methodName is one of the methods listed below.0: added type property.

form1.lastName.value. Each text field has an onChange event handler that converts the field value to uppercase if the checkbox is checked.form1.value.toUpperCase() document.value = document.checked) { field.firstName.toUpperCase() document.value = document.htm (44 of 59) [30/08/2003 9:34:12 PM] .convertUpper.form1.value = document.toUpperCase() } </SCRIPT> <BODY> <FORM NAME="form1"> <B>Last name:</B> <INPUT TYPE="text" NAME="lastName" SIZE=20 onChange="convertField(this)"> <BR><B>First name:</B> <INPUT TYPE="text" NAME="firstName" SIZE=20 onChange="convertField(this)"> <BR><B>City:</B> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.lastName. The following example contains a form with three text boxes and one checkbox.htm q q q blur click eval q q q focus toString valueOf Event handlers q q q onBlur onClick onFocus Examples Example 1.form1. The user can use the checkbox to choose whether the text fields are converted to uppercase.form1.cityName.value = field. The following example displays a group of four checkboxes that all appear checked by default: <B>Specify <BR><INPUT <BR><INPUT <BR><INPUT <BR><INPUT your music preferences (check all that apply):</B> TYPE="checkbox" NAME="musicpref_rnb" CHECKED> R&B TYPE="checkbox" NAME="musicpref_jazz" CHECKED> Jazz TYPE="checkbox" NAME="musicpref_blues" CHECKED> Blues TYPE="checkbox" NAME="musicpref_newage" CHECKED> New Age Example 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.toUpperCase()} } function convertAllFields() { document.form1.cityName.form1.value.firstName. The checkbox has an onClick event handler that converts all fields to uppercase when the user checks the checkbox.value. <HTML> <HEAD> <TITLE>Checkbox object example</TITLE> </HEAD> <SCRIPT> function convertField(field) { if (document.

radioName is the value of the NAME attribute of a Radio object. radioName[index].file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.checked 2.htm (45 of 59) [30/08/2003 9:34:12 PM] .htm <INPUT TYPE="text" NAME="cityName" SIZE=20 onChange="convertField(this)"> <P><INPUT TYPE="checkBox" NAME="convertUpper" onClick="if (this. Radio objects checked Property. Syntax 1. Radio Implemented in Navigator 2. Property of Checkbox.checked Parameters checkboxName is either the value of the NAME attribute of a Checkbox object or an element in the elements array.0 Tainted? Yes file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.checked) {convertAllFields()}" > Convert fields to upper case </FORM> </BODY> </HTML> See also Form object. checkboxName. A Boolean value specifying the selection state of a Checkbox object or radio button. index is an integer representing a radio button in a Radio object.

You can set the checked property at any time. Method of Frame object.htm Description If a checkbox or radio button is selected. function stateChecker() { var checkedButton = "" for (var i in document.musicType[i].checked=="1") { checkedButton=document.musicType) { if (document. Cancels a timeout that was set with the setTimeout method. The VALUE attribute of the selected button is assigned to the checkedButton variable. Syntax clearTimeout(timeoutID) Parameters timeoutID is a timeout setting that was returned by a previous call to the setTimeout method. otherwise. it is false. Examples The following example examines an array of radio buttons called musicType on the musicForm form to determine which button is selected.value } } } See also defaultChecked property clearTimeout Method. the value of its checked property is true.htm (46 of 59) [30/08/2003 9:34:12 PM] .musicType[i]. The display of the checkbox or radio button updates immediately when you set the checked property.musicForm.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.musicForm. window object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.musicForm.

Checkbox. Method of Button. Syntax 1. Examples See the examples for the setTimeout method. radioName[index]. See also setTimeout method click Method. Simulates a mouse-click on the calling form element. Reset object. index is an integer representing a radio button in a Radio object. Reset. radioName is the value of the NAME attribute of a Radio object or an element in the elements array. or Submit object or an element in the elements array.htm (47 of 59) [30/08/2003 9:34:12 PM] . Submit object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.click() 2.0 Description See the description for the setTimeout method. buttonName. checkboxName is either the value of the NAME attribute of a Checkbox object or an element in the elements array.click() 3. checkboxName. Radio.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.click() Parameters buttonName is either the value of the NAME attribute of a Button.htm Implemented in Navigator 2.

0 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.musicType[0]. Syntax document. selects a radio button. performs the same action as clicking the button.htm (48 of 59) [30/08/2003 9:34:12 PM] . and submit.htm Implemented in Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. For a checkbox. reset.musicForm. checks the checkbox and sets its value to "on. For a radio." The click method does not trigger an object's onClick event handler.click() The following example toggles the selection status of the newAge checkbox on the musicForm form: document.close() Method of document Implemented in Navigator 2.musicForm. Examples The following example toggles the selection status of the first radio button in the musicType Radio object on the musicForm form: document.click() close (document object) Method.newAge. Closes an output stream and forces data sent to layout to display.0 Description The effect of the click method varies according to the calling element: q q q For button.

document. write. such as <BIG> and <CENTER>. The document. Font style tags. as described in the window object. Syntax windowReference.write(myString + "<P>") msgWindow.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Method of window object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. function windowWriter1() { var myString = "Hello. the close method forces the content of the stream to display. world!" msgWindow. automatically flush a layout stream.close() method forces the content of the stream to display in the window.htm Description The close method closes a stream opened with the document. Examples The following function calls document.close() to close a stream that was opened with document.close() } See also open (document object). If the stream was opened to layout.close() Parameters windowReference is a valid way of referring to a window.open().document.document. The close method also stops the "meteor shower" in the Netscape icon and displays "Document: Done" in the status bar. writeln methods close (window object) Method.htm (49 of 59) [30/08/2003 9:34:12 PM] . Closes the specified window.open() method.open() msgWindow.

Description The close method closes the specified window. a call to close() without specifying an object name is equivalent to document. the close method closed any window. Examples Any of the following examples closes the current window: window. This is a security feature to prevent "mail bombs" containing self. In previous release.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. In event handlers. If you call close without specifying a windowReference. If you attempt to close any other window.close() instead of simply using close().0 Navigator 3.htm (50 of 59) [30/08/2003 9:34:12 PM] . you must specify window.htm Implemented in q q Navigator 2.close(). However.close().0: closes only windows opened by JavaScript. if the window has only one document (the current one) in its session history. which lets the user choose whether the window closes.open("") See also closed property. the close is allowed without any confirm. Due to the scoping of static objects in JavaScript. open (window object) method closed file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.close() close() The following example closes the messageWin window: messageWin. JavaScript closes the current window. The close method closes only windows opened by JavaScript using the open method.close() This example assumes that the window was opened in a manner similar to the following: messageWin=window. a confirm is generated. This is a special case for one-off windows that need to open other windows and then dispose of themselves.close() self.

html'. A function is called depending on whether win1 is closed. When a window closes. The following code opens a window.htm (51 of 59) [30/08/2003 9:34:12 PM] .'width=300. Once a window is closed. you should not attempt to manipulate it. as described in the window object. and its closed property is set to true. if (win1.. then later checks to see if that window has been closed.open()'s return value). Specifies whether a window is closed. win1=window.htm Property.closed) function1() else function2() file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.open('opener1.0 Tainted? No Description The closed property is a boolean value that specifies whether a window has been closed. Syntax [windowReference.]closed Parameters windowReference is a valid way of referring to a window. Use closed to determine whether a window that you opened. is still open. win1. the window object that represents it continues to exist. and to which you still hold a reference (from window..height=300') . Property of window object Implemented in Navigator 3. closed is a read-only property. Examples Example 1.'window1'.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.

A boolean value that indicates whether Navigator has completed its attempt to load an image. Examples file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.closed) function1() else function2() See also close (window object).0 Tainted? No Description complete is a read-only property.complete Parameters imageName is either the name of an Image object or an element in the images array. Syntax imageName. open (window object) methods complete Property. The following code determines if the current window's opener window is still closed.htm Example 2. Property of Image Implemented in Navigator 3. and calls the appropriate function.opener.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. if (window.htm (52 of 59) [30/08/2003 9:34:12 PM] .

gif'">F-15 Eagle 2 <BR><INPUT TYPE="radio" NAME="imageChoice" VALUE="image3" onClick="document. src properties confirm Method.src='f15e2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.images[0].images[0].htm The following example displays an image and three radio buttons. Method of window object Implemented in Navigator 2.0 Description file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.htm (53 of 59) [30/08/2003 9:34:12 PM] . The user can click the radio buttons to choose which image is displayed. Clicking another button lets the user see the current value of the complete property.complete)"> <BR> <IMG NAME="aircraft" SRC="f15e.gif" ALIGN="left" VSPACE="10"><BR> See also lowsrc. <B>Choose an image:</B> <BR><INPUT TYPE="radio" NAME="imageChoice" VALUE="image1" CHECKED onClick="document.gif'">AH-64 Apache <BR><INPUT TYPE="button" VALUE="Is the image completely loaded?" onClick="alert('The value of the complete property is ' + document.src='ah64. Syntax confirm("message") Parameters message is any string or a property of an existing object.gif'">F-15 Eagle <BR><INPUT TYPE="radio" NAME="imageChoice" VALUE="image2" onClick="document.images[0].src='f15e.images[0]. Displays a Confirm dialog box with the specified message and OK and Cancel buttons.

See open (window object). Syntax objectType. function confirmCleanUp() { if (confirm("Are you sure you want to quit this application?")) { cleanUp() } } You can call the confirmCleanUp function in the onClick event handler of a form's pushbutton. windowReference. the custom cleanUp function closes the application. as shown in the following example: <INPUT TYPE="button" VALUE="Quit" onClick="confirmCleanUp()"> See also alert. but you can use the open method to create your own "confirm" dialog. The confirm method returns true if the user chooses OK and false if the user chooses Cancel.htm (54 of 59) [30/08/2003 9:34:12 PM] . Although confirm is a method of the window object.htm A confirm dialog box looks as follows: Click for sample confirm dialog box Use the confirm method to ask the user to make a decision that requires either an OK or a Cancel. prompt methods constructor Property. If the user chooses OK. you do not need to specify a windowReference when you call it. Specifies the function that creates an object prototype.confirm() is unnecessary.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. The message argument specifies a message that prompts the user for the decision. Examples This example uses the confirm method in the confirmCleanUp function to confirm that the user of an application really wants to quit. You cannot specify a title for a confirm dialog box. For example.constructor file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.

0 Tainted? No Description Each prototype object has a constructor property that refers to the function that created the object.writeln("<B>theTree. function Tree(name) { this. } See also prototype property. Property of constructor is a property of any prototype object (see "Creating new objects"). Examples The following example creates a prototype object.htm Parameters objectType is the name of a constructor or function specifying an object type. theTree. Tree and an object of that type.name=name } theTree = new Tree("Redwood") document.htm (55 of 59) [30/08/2003 9:34:12 PM] .name = name.constructor is function Tree(name) { this.constructor is</B> " + theTree. The example then displays the constructor property for the object theTree. "Creating new objects" cookie file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.constructor + "<P>") This example displays the following output: theTree.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. Implemented in Navigator 3.

You can set the cookie property at any time. respectively. HH. a valid cookie expiration date is expires=Wednesday. This date string is formatted as follows: Wdy. YY is an integer representing the last two digits of the year. The "expires=" component in the cookie file sets an expiration date for the cookie. 09-Nov-99 23:12:40 GMT The cookie date format is the same as the date returned by toGMTString. Mon is a string representing the three-character abbreviation of the month. DD is an integer representing the day of the month.txt file. DD-Mon-YY HH:MM:SS GMT This format represents the following values: q q q q q Wdy is a string representing the full name of the day of the week.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.htm (56 of 59) [30/08/2003 9:34:13 PM] . and lastIndexOf to determine the value stored in the cookie. MM. String value of a cookie.htm Property. and SS are two-digit representations of hours.cookie Property of document Implemented in Navigator 2. minutes. "Netscape cookies" for a complete specification of the cookie syntax. which is a small piece of information stored by the Navigator in the cookies. indexOf.0 Tainted? Yes Description Use string methods such as substring. so it persists beyond the current browser session. with the following exceptions: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. See the Appendix D. For example. and seconds. charAt. Syntax document.

htm q q Dashes are added between the day. semicolon." // set the cookie expiration time to one day // beyond the reminder time document. Method of Math file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. The cookie expiration date is set to one day after the date of the reminder. onto an encoded expression.htm (57 of 59) [30/08/2003 9:34:13 PM] . Syntax Math. // returned by Date.getTime().cos(number) Parameters number is a numeric expression representing the size of an angle in radians. The year is a two-digit value for cookies. expression) { // Record a cookie of the form "@<T>=<E>" to map // from <T> in milliseconds since the epoch.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. or a property of an existing object. month. // or comma characters) document.cookie += "expires=" + cookieDate(time + 24*60*60*1000) // cookieDate is a function that formats the date //according to the cookie spec } See also Hidden object cos Method. // <E> (encoded to contain no white space. Returns the cosine of a number. and year. function RecordReminder(time. Examples The following function uses the cookie property to record a reminder for users of an application.cookie = "@" + time + "=" + expression + ".

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. tan methods current Property.htm (58 of 59) [30/08/2003 9:34:13 PM] .htm Implemented in Navigator 2. getCos returns 6.PI/2. Syntax history.PI.cos(x) } If x equals Math.123031769111886e-017. which represents the cosine of the angle. asin. atan.0 Description The cos method returns a numeric value between -1 and one. getCos returns -1. Examples The following function returns the cosine of the variable x: function getCos(x) { return Math. atan2. A string specifying the complete URL of the current history entry.current Property of history object Implemented in Navigator 3. if x equals Math. See also acos.0 Tainted? Yes file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. sin.

current) } See also next. current is a read-only property.current. Examples The following example determines whether history. current has no value. if (history. If it does.com") != -1) { myFunction(history.htm (59 of 59) [30/08/2003 9:34:13 PM] . previous properties.indexOf("netscape.com".htm Description The current property has a value only if data tainting is enabled. "Using data tainting for security" [Next reference file] file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c. if data tainting is not enabled. the function myFunction is called.current contains the string "netscape.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_a-c.

3. hours. month.UTC(parameters) Date. they are integer values. seconds) To use a Date object: 1. Syntax To create a Date object: 1. day. minutes. Property of None Implemented in q q Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. year. day. 2.0: added prototype property file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.htm [Previous reference file] Date Object.methodName(parameters) Exceptions: The Date object's parse and UTC methods are static methods that you use as follows: Date. hours. 4.htm (1 of 26) [30/08/2003 9:34:14 PM] . dateObjectName dateObjectName dateObjectName dateObjectName = = = = new new new new Date() Date("month day. dateObjectName. Lets you work with dates and times. dateObjectName. When using Date properties and methods. methodName is one of the methods listed below. month. dateObjectName is either the name of an existing Date object or a property of an existing object.propertyName 2. year hours:minutes:seconds") Date(year.0 Navigator 3. For forms 3 and 4. minutes. and seconds are string values for form 2 of the syntax. day) Date(year. propertyName is one of the properties listed below.parse(parameters) Parameters dateObjectName is either the name of a new object or a property of an existing object. month.

1995 03:24:00") file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. or seconds from form 2 or 4 of the syntax. Properties The Date object has the following properties: Property Description prototype Lets you add a properties to a Date object. Methods The Date object has the following methods: q q q q q q q q q q q q eval getDate getDay getHours getMinutes getMonth getSeconds getTime getTimezoneOffset getYear parse setDate q q q q q q q q q q q setHours setMinutes setMonth setSeconds setTime setYear toGMTString toLocaleString toString UTC valueOf Event handlers None. Dates prior to 1970 are not allowed. If you omit hours.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. and both store dates internally as the number of milliseconds since January 1. the value will be set to zero. minutes.htm Description The Date object is a built-in JavaScript object. The way JavaScript handles dates is very similar to the way Java handles dates: both languages have many of the same date methods. 1970 00:00:00.htm (2 of 26) [30/08/2003 9:34:14 PM] . Form 1 of the syntax creates today's date and time. Examples The following examples show several ways to assign dates: today = new Date() birthday = new Date("December 17.

otherwise.0 Tainted? Yes Description If a checkbox or radio button is selected by default.0) defaultChecked Property. it is false. Examples file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.defaultChecked 2. A Boolean value indicating the default selection state of a checkbox or radio button. however.17) birthday = new Date(95. defaultChecked initially reflects whether the CHECKED attribute is used within an <INPUT> tag. radioName is the value of the NAME attribute of a Radio object. radioName[index].3. Syntax 1. You can set the defaultChecked property at any time.htm (3 of 26) [30/08/2003 9:34:14 PM] . index is an integer representing a radio button in a Radio object.defaultChecked Parameters checkboxName is either the value of the NAME attribute of a Checkbox object or an element in the elements array.17. Radio Implemented in Navigator 2.24. only when you set the checked property. Property of Checkbox. setting defaultChecked overrides the CHECKED attribute.htm birthday = new Date(95.12.12. the value of the defaultChecked property is true. The display of the checkbox or radio button does not update when you set the defaultChecked property. checkboxName.

musicType[i]. Property of Option object (see Select object).musicForm.defaultChecked==true) { document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.musicType[i]. index is an integer representing an option in a Select object. options array (see Select object) Implemented in q q Navigator 2.0 Navigator 3.options[index].0: property of Option object Tainted? file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.musicForm.musicForm.htm The following example resets an array of radio buttons called musicType on the musicForm form to the default selection state: function radioResetter() { var i="" for (i in document. optionName is the name of a Select object option created using the Option() constructor.checked=true } } } See also checked property defaultSelected Property.defaultSelected Parameters selectName is either the value of the NAME attribute of a Select object or an element in the elements array. Syntax selectName.defaultSelected optionName. A Boolean value indicating the default selection state of an option in a Select object.htm (4 of 26) [30/08/2003 9:34:14 PM] .musicType) { if (document.

i++) { if (document. otherwise.defaultSelected == true) { document. Examples In the following example. defaultSelected initially reflects whether the SELECTED attribute is used within an <OPTION> tag. The if statement sets the selected property if defaultSelected is true. The for loop uses the options array to evaluate every option in the Select object. any previous default selections.musicType. When you set defaultSelected in such an object. The display of the Select object does not update when you set the defaultSelected property. including defaults set with the SELECTED attribute.musicForm. You can set the defaultSelected property at any time.options[i].htm (5 of 26) [30/08/2003 9:34:14 PM] . are cleared.htm Yes Description If an option in a Select object is selected by default.options[i]. the restoreDefault function returns the musicType Select object to its default state. i < document. it is false. selectedIndex properties defaultStatus file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. however. A Select object created without the MULTIPLE attribute can have only one option selected by default.musicType.length.musicForm. the value of the defaultSelected property is true.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. selected. If you set defaultSelected in a Select object created with the MULTIPLE attribute.musicForm. only when you set the selected or selectedIndex properties. function restoreDefault() { for (var i = 0. previous default selections are not affected.selected=true } } } The previous example assumes that the Select object is similar to the following: <SELECT NAME="musicType"> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT> See also index. setting defaultSelected overrides the SELECTED attribute.musicType.

You must return true to set status or defaultStatus in an event handler.defaultStatus Parameters windowReference is a valid way of referring to a window. the statusSetter function sets both the status and defaultStatus properties in an onMouseOver event handler: function statusSetter() { window.com" onMouseOver = "statusSetter(). Do not confuse the defaultStatus property with the status property.htm (6 of 26) [30/08/2003 9:34:14 PM] . file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. as described in the window object. The default message displayed in the status bar at the bottom of the window.htm Property.status = "Netscape home page" } <A HREF="http://home. You must return true if you want to set the defaultStatus property in the onMouseOut or onMouseOver event handlers.defaultStatus = "Click the link for the Netscape home page" window. such as the message that appears when a mouseOver event occurs over an anchor.0 Tainted? Yes Description The defaultStatus message appears when nothing else is in the status bar. Syntax windowReference. Property of window object Implemented in Navigator 2. The status property reflects a priority or transient message in the status bar. Examples In the following example. You can set the defaultStatus property at any time. notice that the onMouseOver event handler returns a value of true. return true">Netscape</A> In the previous example.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.netscape.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. textareaName.htm See also status property defaultValue Property. textareaName is either the value of the NAME attribute of a Textarea object or an element in the elements array. A string indicating the default value of a Password. or Textarea object. regardless of the value of the VALUE attribute. passwordName. For Textarea objects. Text object. Textarea object Implemented in Navigator 2. Property of Password object. Syntax 1. textName is either the value of the NAME attribute of a Text object or an element in the elements array.defaultValue 2. For Password objects. textName.defaultValue 3. it initially reflects the value of the VALUE attribute. If you programmatically set defaultValue for the file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. Setting defaultValue programmatically overrides the initial setting.defaultValue Parameters passwordName is either the value of the NAME attribute of a Password object or an element in the elements array. it initially is null (for security reasons).0 Tainted? Yes Description The initial value of defaultValue differs for each object: q q q For Text objects.htm (7 of 26) [30/08/2003 9:34:14 PM] . Text. it initially reflects the value specified between the <TEXTAREA> and </TEXTAREA> tags.

write("password.open("") msgWindow.document. index2 is either an integer representing a plug-in installed on the client or a string containing the name of a Plugin object (from the name property). only when you set the value property.defaultValue is " + document.mimeTypes[index1].surfCity.textareaObj.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.plugins[index2].defaultValue + "<BR>") msgWindow.document. A description of a MIME type or plug-in. You can set the defaultValue property at any time.textObj.passwordObj.description 2.htm (8 of 26) [30/08/2003 9:34:14 PM] . navigator.defaultValue is " + document.surfCity. Syntax 1.description Parameters index1 is either an integer representing a MIME type supported by the client or a string containing the type of a MimeType object (from the type property).defaultValue is " + document.write("text.write("hidden.hiddenObj.htm Password object and then evaluate it.write("textarea.defaultValue + "<BR>") msgWindow. JavaScript returns the current value.document. Examples The following function evaluates the defaultValue property of objects on the surfCity form and displays the values in the msgWindow window: function defaultGetter() { msgWindow=window.document.defaultValue is " + document.close() } See also value property description Property.surfCity. The display of the related object does not update when you set the defaultValue property.surfCity.defaultValue + "<BR>") msgWindow. navigator. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.defaultValue + "<BR>") msgWindow.document.

Examples See the examples for the MimeType and Plugin objects. length. suffixes properties For Plugin objects: filename. The description is supplied by the plug-in itself. and provides methods for displaying HTML output to the user. For Plugin objects. the description property is a description of the plug-in. See also For MimeType objects: enabledPlugin.htm Property of q q MimeType Plugin Implemented in Navigator 3.htm (9 of 26) [30/08/2003 9:34:14 PM] . Contains information on the current document. the description property is a description of the content and encoding for the MIME data type. use standard HTML syntax with the addition of JavaScript event handlers: <BODY BACKGROUND="backgroundImage" BGCOLOR="backgroundColor" TEXT="foregroundColor" file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. type. HTML syntax To define a document object. description is a read-only property.0 Tainted? No Description For MimeType objects.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. name properties document Object.

You can load a new document by using the window.methodName(parameters) Parameters propertyName is one of the properties listed below.htm (10 of 26) [30/08/2003 9:34:14 PM] . document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.htm LINK="unfollowedLinkColor" ALINK="activatedLinkColor" VLINK="followedLinkColor" [onBlur="handlerText"] [onFocus="handlerText"] [onLoad="handlerText"] [onUnload="handlerText"]> </BODY> HTML attributes BACKGROUND specifies an image that fills the background of the document.0: added onBlur and onFocus syntax. and VLINK are color specifications expressed as a hexadecimal RGB triplet (in the format "rrggbb" or "#rrggbb") or as one of the string literals listed in "Color values". Property of window object Implemented in q q Navigator 2. TEXT. BGCOLOR. document. Syntax To use a document object's properties and methods: 1. added applets. and images properties. embeds.0 Navigator 3. LINK. The <BODY> tag encloses the body of a document. and Plugin objects as properties Description An HTML document consists of <HEAD> and <BODY> tags. which is defined by the current URL. domain. methodName is one of the methods listed below. Area.propertyName 2. ALINK. added Applet. The entire body of the document (all other HTML elements for the document) goes within the <BODY> tag. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. The <HEAD> tag includes information on the document's title and base (the absolute URL base to be used for relative URL links in the document).location object. Image.

and links of a document by using the anchors.htm (11 of 26) [30/08/2003 9:34:14 PM] .open() call if you are writing text or HTML. You can omit the document. Do not use location as a property of the document object. since write does an implicit open of that mime type if the document stream is closed. The document. Properties The document object has the following properties: Property alinkColor anchors applets bgColor cookie domain Description Reflects the ALINK attribute An array reflecting all the anchors in a document An array reflecting all the applets in a document Reflects the BGCOLOR attribute Specifies a cookie Specifies the domain name of the server that served a document embeds array An array reflecting all the plugins in a document fgColor forms images Reflects the TEXT attribute An array reflecting all the forms in a document An array reflecting all the images in a document lastModified Reflects the date a document was last modified linkColor links referrer title URL vlinkColor Reflects the LINK attribute An array reflecting all the links in a document Reflects the URL of the calling document Reflects the contents of the <TITLE> tag Reflects the complete URL of a document Reflects the VLINK attribute The following objects are also properties of the document object: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.URL. You can reference the anchors. form. use the document. will be removed in a future release. and so on so they do not redisplay) by using document.close(). or link in a document.write(). document. forms. forms. These arrays contain an entry for each anchor. which is a synonym for document. and links arrays.open().htm You can clear the document pane (and remove the text. document.URL property instead.location property. form elements.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.

onLoad. onFocus. Examples The following example creates two frames. which defines the content for the first frame.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.html.html" NAME="frame2"> </FRAMESET> </HTML> doc1.70%"> <FRAME SRC="doc1. and onUnload event handlers are specified in the <BODY> tag but are actually event handlers for the window object. Each document defines its colors. which defines the frames. contains the following code: <HTML> <SCRIPT> </SCRIPT> <BODY BGCOLOR="antiquewhite" file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. contains the following code: <HTML> <HEAD> <TITLE>Document object example</TITLE> </HEAD> <FRAMESET COLS="30%. The onBlur. doc0.html.html" NAME="frame1"> <FRAME SRC="doc2. each with one document. The document in the first frame contains links to anchors in the document of the second frame.htm q q q Anchor object Applet Area (see Link object) q q q Form object Image Link object Methods The document object has the following methods: q q q q close (document object) eval open (document object) toString q q q valueOf write writeln Event handlers None.htm (12 of 26) [30/08/2003 9:34:14 PM] .

html#colors" TARGET="frame2">Colors</A> <LI><A HREF="doc2.html#numbers" TARGET="frame2">Numbers</A> <LI><A HREF="doc2. contains the following code: <HTML> <SCRIPT> </SCRIPT> <BODY BGCOLOR="oldlace" onLoad="alert('Hello. window object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.html#musicTypes" TARGET="frame2">Music types</A> <LI><A HREF="doc2. which defines the content for the second frame.html. World.htm (13 of 26) [30/08/2003 9:34:14 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.html#countries" TARGET="frame2">Countries</A> </BODY> </HTML> doc2.')" TEXT="navy"> <P><A NAME="numbers"><B>Some numbers</B></A> <UL><LI>one <LI>two <LI>three <LI>four</UL> <P><A NAME="colors"><B>Some colors</B></A> <UL><LI>red <LI>orange <LI>yellow <LI>green</UL> <P><A NAME="musicTypes"><B>Some music types</B></A> <UL><LI>R&B <LI>Jazz <LI>Soul <LI>Reggae</UL> <P><A NAME="countries"><B>Some countries</B></A> <UL><LI>Afghanistan <LI>Brazil <LI>Canada <LI>Finland</UL> </BODY> </HTML> See also Frame object.htm TEXT="darkviolet" LINK="fuchsia" ALINK="forestgreen" VLINK="navy"> <P><B>Some links</B> <LI><A HREF="doc2.

domain Property of document Tainted? Yes Implemented in Navigator 3. these two scripts can share properties.0 Description The domain property lets scripts on multiple servers share properties when data tainting is not enabled.com". you cannot reset it to "search.com". if you change domain from "search.com" to "yahoo. But large Web sites with multiple servers might need to share properties among servers. You can change domain at any time.yahoo.yahoo. For example. even though they did not originate from the same server.yahoo.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.htm (14 of 26) [30/08/2003 9:34:14 PM] . You can set domain only to a domain suffix of itself.yahoo.yahoo.com could set its domain property to "yahoo. a script running in one window can read properties of another window only if both windows come from the same Web server. domain contains the hostname of the Web server from which the document was loaded. a script loaded from search. Specifies the domain name of the server that served a document.com". Once you change the domain property. a script from search.com".htm domain Property. Then. And a script from IWantYourMoney. Initially.yahoo". You can change domain only in a restricted way. Examples The following statement changes the domain property to "braveNewWorld. This statement is valid only if file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.com".yahoo. since both scripts have the domain "yahoo.com can't set its domain property to "search. A script from www. For example. both scripts can share properties.com running in another window could also set its domain property to "yahoo. For example. a script on the host www.com".com cannot set its domain to "yahoo.com".com.com might need to share properties with a script on the host search.yahoo. With tainting disabled. If scripts on two different servers change their domain property so that both scripts have the same domain name. For example. Syntax document. you cannot change it back to its original value.

htm (15 of 26) [30/08/2003 9:34:14 PM] . "Using data tainting for security" E Property.htm "braveNewWorld. approximately 2.718.com" is a suffix of the current domain.E } See also file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. document. it is a read-only property of Math.braveNewWorld.com" See also taint. such as "www. untaint functions.domain="braveNewWorld. Syntax Math. Examples The following function returns Euler's constant: function getEuler() { return Math.E Property of Math Implemented in Navigator 2.0 Tainted? No Description Because E is a constant. Euler's constant and the base of natural logarithms.com".

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. LOG10E. formName. SQRT1_2. Submit.elements[index] 2. these elements are reflected as formName. LN10.elements[1].elements. Although you can also reference a form's elements by using the element's name (from the NAME attribute). FileUpload. PI.length Parameters formName is either the name of a form or an element in the forms array.htm (16 of 26) [30/08/2003 9:34:14 PM] . and Text objects) in source order. Syntax 1. or Textarea object) in a form in source order. Select. An array of objects corresponding to form elements (such as checkbox. LOG2E.value file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. Radio.htm exp. Property of Form object Implemented in Navigator 2.value userInfo.elements[2]. LN2.userName. formName. you can evaluate it in either of the following ways: userInfo. Hidden. This array contains an entry for each object (Button. and formName. SQRT2 properties elements array Property. For example.0 Tainted? No Description You can reference a form's elements in your code by using the elements array. Reset. formName. if a form has a text field and two checkboxes. the elements array provides a way to reference Form objects programmatically without using their names.elements[0]. Text. index is an integer representing an object on a form or the name of an object as specified by the NAME attribute. Checkbox. if the first object on the userInfo form is the userName Text object. For example. radio.elements[0]. Password.

Each radio button in a Radio object appears as a separate element in the elements array.htm (17 of 26) [30/08/2003 9:34:14 PM] . An array of objects corresponding to form elements (such as Checkbox.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. embeds array Property. An array reflecting all the <EMBED> tags in a document in source order. the statement formName. use standard HTML syntax: <EMBED SRC=source NAME=embedName HEIGHT=height file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.elements[0]="music" has no effect. and Text objects) in source order. HTML syntax To generate output from a plug-in application. use the length property: formName. See also Form object elements property Property. See the elements array for information.htm To obtain the number of elements on a form. For example.length.elements. Elements in the elements array are read-only. Properties The elements array has the following properties: Property Description length Reflects the number of elements in the form Examples See the examples for the Frame property. The value of each element in the elements array is the full HTML statement for the object. Radio.

See Chapter 4.embeds. NAME=embedName specifies the name of the embedded object in the document.0 Tainted? No Description You can reference embedded objects (created with the <EMBED> tag) in your code by using the embeds array. For example. document. This array contains an entry for each <EMBED> tag in a document in source order.htm (18 of 26) [30/08/2003 9:34:14 PM] . document. document.embeds[0]. You can use this name when indexing the embeds array.. Property of document Implemented in Navigator 3. and document..embeds[index] 2.html. HEIGHT=height specifies the height of the applet in pixels within the browser window.length file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. Elements in the embeds array may have public callable functions.0/handbook/plugins/index.embeds[2]. if they reference a "LiveConnected" plug-in. WIDTH=width specifies the width of the applet in pixels within the browser window.com/eng/mozilla/3.htm WIDTH=width> [parameterName=parameterValue] [ . "LiveConnect. these <EMBED> tags are reflected as document. if a document contains three <EMBED> tags.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. parameterName=parameterValue] </EMBED> For the complete syntax of the <EMBED> tag.netscape.embeds[1]. see http://home. parameterName=parameterValue specifies the name and value of a parameter to pass to the embedded object's plug-in. HTML attributes SRC=source</I> specifies the URL containing the source content." To use the embeds array: 1.

Event handlers q None.length. use the length property: document.avi" has no effect. Elements in the embeds array are read-only. To obtain the number of <EMBED> tags in a document. you are not creating a Plugin object. Examples The following code includes an audio plug-in in a document. you cannot do anything with its element in the embeds array.embeds. <EMBED SRC="train. Use the elements in the embeds array to interact with the plug-in that is displaying the embedded object.htm index is an integer representing an <EMBED> tag or the name of an embedded object as specified by the NAME attribute. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. The fields and methods of the elements in the embeds array vary from plug-in to plug-in.htm (19 of 26) [30/08/2003 9:34:14 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.au" HEIGHT=50 WIDTH=250> See also Plugin object enabledPlugin Property. The Plugin object for the plug-in that is configured for the specified MIME type. For example. See the Plugin object. Properties The embeds array has the following properties: Property Description length Reflects the number of elements in the array Methods q None.embeds[0]="myavi. the statement document. see the documentation supplied by the plug-in manufacturer. When you use the <EMBED> tag to generate output from a plug-in application. If a plug-in is not Java-enabled.

However. and each MIME type could potentially be supported by multiple plug-ins. only one plug-in can be configured for a MIME type.enabledPlugin Parameters index is either an integer representing a MIME type supported by the client or a string containing the type of a MimeType object (from the type property).mimeTypes[index]. the user can configure the handler for each MIME type. the handler is determined at Navigator start-up time.) The enabledPlugin property is a reference to a Plugin object that represents the plug-in that is configured for the specified MIME type. so can we display with a plug-in? plugin = mimetype. If it is. enabledPlugin is a read-only property. a movie is displayed.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. But you could not determine whether a plug-in is configured for the MIME type. (On Macintosh and Unix. // Can we display Shockwave movies? mimetype = navigator. so you could dynamically emit an <EMBED> tag on the page if the user has a plug-in configured for the MIME type. If the MIME type does not have a plug-in configured. on Windows.htm Syntax navigator.enabledPlugin file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.0 Tainted? No Description Use the enabledPlugin property to determine which plug-in is configured for a specific MIME type. Examples The following example determines whether the Shockwave plug-in is installed. if their Navigator can handle a particular MIME type. enabledPlugin is null. you could determine if the user has a particular plug-in installed. You might need to know this information. Without the enabledPlugin property.mimeTypes["application/x-director"] if (mimetype) { // Yes. Each plug-in may support multiple MIME types. and if the MIME type is supported by any plug-ins.htm (20 of 26) [30/08/2003 9:34:14 PM] . Property of MimeType Implemented in Navigator 3. for example.

writeln("<A HREF='mymovie.dir HEIGHT=100 WIDTH=100>") else // No.htm (21 of 26) [30/08/2003 9:34:14 PM] .") } else { // No.writeln("Here\'s a movie: <EMBED SRC=mymovie.encoding Parameters formName is either the name of a form or an element in the forms array. type.htm if (plugin) // Yes.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. so show the data in-line document. can't show you this cool movie.") } See also the examples for the MimeType object. Syntax formName. A string specifying the MIME encoding of the form.dir>Click here</A> to see a movie.0 Tainted? No Description file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. See also description. so tell them so document. so provide a link to the data document.writeln("Sorry. suffixes properties encoding Property. Property of Form object Implemented in Navigator 2.

Examples The following example returns "Hello%2C%20World": file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.htm The encoding property initially reflects the ENCTYPE attribute of the <FORM> tag. Implemented in Navigator 2. or a property of an existing object. target properties.musicForm. Examples The following function returns the value of the musicForm encoding property: function getEncoding() { return document. the escape function returns the same character. escape is a top-level function not associated with any object. method.0 Description The value returned by the escape function is a string of the form "%xx.encoding } See also action. Syntax escape("string") Parameters string is a nonalphanumeric string in the ISO Latin-1 character set. Returns the ASCII encoding of an argument in the ISO Latin-1 character set. If you pass the escape function an alphanumeric character." where xx is the ASCII encoding of a character in the argument.htm (22 of 26) [30/08/2003 9:34:14 PM] . setting encoding overrides the ENCTYPE attribute.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. You can set the encoding property at any time. Form object escape Function. however.

not associated with any object. statement. eval evaluates the expression. World") The following example returns "%26": escape("&") The following example returns "%21%23": escape("!#") See also unescape function eval Method. Implemented in Navigator 2.htm (23 of 26) [30/08/2003 9:34:14 PM] .0: a built-in JavaScript function. or sequence of statements.htm escape("Hello. If the file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. but part of the language itself Navigator 3. the string is evaluated without regard to any object.]eval(string) Parameters objectName is the object for which a string is to be evaluated. Syntax [objectName. If omitted. The eval method evaluates a string of JavaScript code in the context of the specified object. string is any string representing a JavaScript expression. If the string represents an expression. Method of eval is a method of all objects.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. The expression can include variables and properties of existing objects.0: a method of every object Description The argument of the eval method is a string.

value") = newValue } Example 5. z = 42. and the write method displays "Lab". var str = "if (x == 5) {alert('z is 42'). The following example creates breed as a property of the object myDog.write("The field named ". The first statement assigns the string value of the third form element to the variable field. say "3 * x + 2".color) { this. to a variable. You can postpone evaluation of an expression involving x by assigning the string value of the expression. and the write method displays "Shepherd". eval performs the statements. you can use eval to evaluate it at a later time.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. " has value of ". In the following example. and also as a variable. and assigns zero to z otherwise. and then calling eval at a later point in your script.forms[0].write("<P>z is ".breed. eval(str)) Example 4.htm (24 of 26) [30/08/2003 9:34:14 PM] . "<BR>") document. The second write statement uses myDog. suppose you have a variable x. " document." var x = 2 var y = 39 var z = "42" document.write(eval("x + y + 1").name=name this. var field = getFieldName(3) document. function Dog(name. If you construct an arithmetic expression as a string. which is the value of the breed variable. In the following example.breed=breed file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e. Examples Example 1. The second statement uses eval to display the value of the form element. eval(field + ". the getFieldName(n) function returns the name of the nth form element as a string. The following example uses eval to evaluate the string str. which is the value of the breed property of the myDog object. and it will also evaluate the set of statements and return the value that is assigned to z. the string "breed" is evaluated without regard to any object. JavaScript evaluates arithmetic expressions automatically." and the second evaluates the string "42. field. the string "breed" is evaluated with regard to the myDog object." + textObject + ". The first evaluates the string "x + y + 1. newValue) { eval ("document. Do not call eval to evaluate an arithmetic expression.eval('breed') which specifies the object myDog. "<BR>") Example 2. This string consists of JavaScript statements that open an Alert dialog box and assigns z a value of 42 if x is five. When the second statement is executed.value")) Example 3. The first write statement uses eval('breed') without specifying an object. eval will cause these statements to be performed. the setValue function uses eval to assign the value of the variable newValue to the text field textObject: function setValue (textObject. Both of the write statements below display 42.write(eval(z).htm argument represents one or more JavaScript statements.} else z = 0. For example.

write("<P>" + eval('breed')) document. and 45.x is " + fred.write("<BR>fred.0 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e."+str) this. y.y) document. flintstone.y is " + fred. where number is the argument.write("<BR>fred.z2 is " + fred.z) document. The statement fred = new flintstone("x=42") creates the object fred with the properties x.write("<BR>" + myDog.exp(number) Parameters number is any numeric expression or a property of an existing object.eval("this.write("<BR>fred.color=color } myDog = new Dog("Gabby") myDog. The following example uses eval within a function that defines an object type.eval("this.z2) exp Method.z is " + fred.htm this. function flintstone(str) { this. the base of the natural logarithms. and e is Euler's constant. 44. Method of Math Implemented in Navigator 2.htm (25 of 26) [30/08/2003 9:34:14 PM] . 43. Returns enumber. and z2.breed="Lab" var breed='Shepherd' document.y=43") this. The write statements display the values of these properties as 42. respectively. Syntax Math.x) document.z=44 this["z2"] = 45 } fred = new flintstone("x=42") document. z.eval('breed')) Example 6.write("<BR>fred.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.

it returns 2.htm Examples The following function returns the exp value of the variable x: function getExp(x) { return Math.718281828459045.exp(x) } If you pass getExp the value 1.htm (26 of 26) [30/08/2003 9:34:14 PM] . See also E. log. pow methods [Next reference file] file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_d-e.

fgColor Property of document Implemented in Navigator 2. Examples The following example sets the color of the foreground text to aqua using a string literal: document." You can override the value set in the fgColor property in either of the following ways: q q Setting the COLOR attribute of the <FONT> tag.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. green=80.htm (1 of 34) [30/08/2003 9:34:17 PM] . the hexadecimal RGB values for salmon are red=FA.fgColor="aqua" The following example sets the color of the foreground text to aqua using a hexadecimal triplet: document. The default value of this property is set by the user on the Colors tab of the Preferences dialog box. which is displayed by choosing General Preferences from the Options menu.htm [Previous reference file] fgColor Property.fgColor="00FFFF" file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. This property is the JavaScript reflection of the TEXT attribute of the <BODY> tag. Using the fontcolor method. and blue=72. A string specifying the color of the document (foreground) text. you must use the format rrggbb. You cannot set this property after the HTML source has been through layout. Syntax document. so the RGB triplet for salmon is "FA8072. For example.0 Tainted? No Description The fgColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in "Color values". If you express the color as a hexadecimal RGB triplet.

linkColor. length. See also description. name properties file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. Syntax 1. vlinkColor properties.plugins[index]. fontcolor method filename Property. filename is a read-only property.0 Tainted? No Description The filename property is the plug-in program's file name and is supplied by the plug-in itself. Examples See the examples for the Plugin object. navigator. navigator. Property of Plugin Implemented in Navigator 3.htm (2 of 34) [30/08/2003 9:34:17 PM] . This name may vary from platform to platform.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.filename Parameters index is either an integer representing a plug-in installed on the client or a string containing the name of a Plugin object (from the name property).htm See also alinkColor. bgColor.plugins[pluginName].filename 2. The name of a plug-in file on disk.

Syntax To use a FileUpload object's properties and methods: fileUploadName.propertyName fileUploadName. Property of Form object Implemented in Navigator 3. A file upload element on an HTML form.methodName Parameters fileUploadName is the value of the NAME attribute of a FileUpload object. A file upload element lets the user supply a file as input.0 Description A FileUpload object on a form looks as follows: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. methodName is one of the properties listed below.htm FileUpload Object. You can access this value using the name property.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. and you can use this name when indexing the elements array. use standard HTML syntax with the addition of JavaScript event handlers: <INPUT TYPE="file" NAME="fileUploadName" [onBlur="handlerText"] [onChange="handlerText"] [onFocus="handlerText"] > HTML attributes NAME="fileUploadName" specifies the name of the FileUpload object (this is not the name of the file to upload). HTML syntax To define a FileUpload object. propertyName is one of the properties listed below.htm (3 of 34) [30/08/2003 9:34:17 PM] .

htm (4 of 34) [30/08/2003 9:34:17 PM] ..htm File containing your entry: Browse..name)"> <INPUT TYPE="button" VALUE="value" onClick="alert('value: ' + document. Properties The FileUpload object has the following properties: Property name type value Description Reflects the NAME attribute Reflects the TYPE attribute Reflects the current value of the file upload element's field.form1.value)"><BR> </FORM> See also Text object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.myUploadObject. This is a read-only property for security purposes. this corresponds to the name of the file to upload.form1.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.myUploadObject. form property Specifies the form containing the FileUpload object Methods The FileUpload object has the following methods: q q q blur eval focus q q toString valueOf Event handlers q q q onBlur onChange onFocus Examples The following example places a FileUpload object on a form and provides two buttons that let the user display current values of the name and value properties. <FORM NAME="form1"> File to send: <INPUT TYPE="file" NAME="myUploadObject"> <P>Get properties<BR> <INPUT TYPE="button" VALUE="name" onClick="alert('name: ' + document. A FileUpload object is a form element and must be defined within a <FORM> tag.

Causes a string to be displayed in fixed-pitch font as if it were in a <TT> tag. Examples The following example uses the fixed method to change the formatting of a string: var worldString="Hello.0 Description Use the fixed method with the write or writeln methods to format and display a string in a document. world" document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. Syntax stringName.fixed() Parameters stringName is any string or a property of an existing object. Syntax Math.htm (5 of 34) [30/08/2003 9:34:17 PM] .fixed()) The previous example produces the same output as the following HTML: <TT>Hello.write(worldString. world</TT> floor Method. Returns the greatest integer less than or equal to a number.floor(number) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm fixed Method. Method of String Implemented in Navigator 2.

focus() Parameters fileUploadName is either the value of the NAME attribute of a FileUpload object or an element in the elements array.focus() frameReference. 3. 5. 7. See also ceil method focus Method. 4. 6. Gives focus to the specified object. fileUploadName. if you pass it the value -45.focus() windowReference. passwordName is either the value of the NAME attribute of a Password object or an element in the elements array.focus() passwordName. it returns 45.focus() selectName. Syntax 1. Method of Math Implemented in Navigator 2.focus() textareaName.95. it returns -46. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. selectName is either the value of the NAME attribute of a Select object or an element in the elements array.95.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.0 Examples The following function returns the floor value of the variable x: function getFloor(x) { return Math. 2.floor(x) } If you pass getFloor the value 45.htm Parameters number is any numeric expression or a property of an existing object.focus() textName.htm (6 of 34) [30/08/2003 9:34:17 PM] .

window.0 Navigator 3. as described in the Frame object. FileUpload object. Frame. choose Release Notes from the Help menu). If the password is not valid. the focus method gives focus to a frame but the focus is not visually apparent (for example. Submit and window Description Use the focus method to navigate to a specific form element. Submit object. Textarea object. function checkPassword(userPass) { if (badPassword) { alert("Please enter your password again. and give it focus.0: method of Button. windowReference is a valid way of referring to a window.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. Radio.htm textName is either the value of the NAME attribute of a Text object or an element in the elements array. textareaName is either the value of the NAME attribute of a Textarea object or an element in the elements array. FileUpload. window object Implemented in q q Navigator 2. Giving focus to a window brings the window forward in most windowing systems. Examples In the following example.select() } } This example assumes that the Password object is defined as <INPUT TYPE="password" NAME="userPass"> See also file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. Reset.focus() userPass.") userPass. Method of Button object. as described in the window object. Please see the release notes (after starting Netscape. frameReference is a valid way of referring to a frame. Checkbox. the frame's border is not darkened). Text object. the checkPassword function confirms that a user has entered a valid password. or frame. Reset object object. the focus method returns focus to the Password object and the select method highlights it so the user can re-enter the password. Checkbox object. Select object. You can then either programmatically enter a value in the form element or let the user enter a value.htm (7 of 34) [30/08/2003 9:34:17 PM] . Frame object. Password object. Note On some platforms. Radio object.

Examples The following example uses the fontcolor method to change the color of a string: var worldString="Hello. If you express color as a hexadecimal RGB triplet.fontcolor("8000") + file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. select method fontcolor Method. world" document. you must use the format rrggbb.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. Syntax stringName.write("<P>" + worldString. color is a string or a property of an existing object. and blue=72.fontcolor("red") + " is red in this line") document.fontcolor(color) Parameters stringName is any string or a property of an existing object.fontcolor("maroon") + " is maroon in this line") document.htm (8 of 34) [30/08/2003 9:34:17 PM] . green=80. Causes a string to be displayed in the specified color as if it were in a <FONT COLOR=color> tag.0 Description Use the fontcolor method with the write or writeln methods to format and display a string in a document." The fontcolor method overrides a value set in the fgColor property.write("<P>" + worldString.write("<P>" + worldString. For example.htm blur method.write(worldString. so the RGB triplet for salmon is "FA8072. expressing the color as a hexadecimal RGB triplet or as one of the string literals listed in "Color values".fontcolor("salmon") + " is salmon in this line") document. Method of String Implemented in Navigator 2. the hexadecimal RGB values for salmon are red=FA.

write("<P>" + worldString. When you specify size as an integer.0 Description Use the fontsize method with the write or writeln methods to format and display a string in a document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. size is an integer between one and seven.htm (9 of 34) [30/08/2003 9:34:17 PM] . world</FONT> is salmon in this line <P><FONT COLOR="red">Hello. you set the size of stringName to one of the seven defined sizes. or a property of an existing object. Syntax stringName. Causes a string to be displayed in the specified font size as if it were in a <FONTSIZE=size> tag. world</FONT> is red in this line <FONT COLOR="8000">Hello. Examples file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. world</FONT> is maroon in this line <P><FONT COLOR="salmon">Hello.htm " is maroon in hexadecimal in this line") document. world</FONT> is salmon in hexadecimal in this line <P><FONT COLOR="FF00">Hello. When you specify size as a string such as "-2.fontcolor("FF00") + " is red in hexadecimal in this line") The previous example produces the same output as the following HTML: <FONT COLOR="maroon">Hello. a string representing a signed integer between one and seven. world</FONT> is maroon in hexadecimal in this line <P><FONT COLOR="FA8072">Hello.fontsize(size) Parameters stringName is any string or a property of an existing object." you adjust the font size of stringName relative to the size set in the <BASEFONT> tag.write("<P>" + worldString. world</FONT> is red in hexadecimal in this line fontsize Method. Method of String Implemented in Navigator 2.fontcolor("FA8072") + " is salmon in hexadecimal in this line") document.

ACTION="serverURL" specifies the URL of the server to which form field input information is sent. use standard HTML syntax with the addition of JavaScript event handlers: <FORM NAME="formName" TARGET="windowName" ACTION="serverURL" METHOD=GET | POST ENCTYPE="encodingType" [onReset="handlerText"] [onSubmit="handlerText"]> </FORM> HTML attributes NAME="formName" specifies the name of the Form object. radio buttons. You can access this value using the target property. or _blank. server responses are displayed in the specified window instead of the window that contains the form.frameName or windowName.small()) document. You can access this value using the name property. This attribute can specify a file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. _self.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. world</BIG> <P><FONTSIZE=7>Hello.htm (10 of 34) [30/08/2003 9:34:17 PM] . or it can be one of the literal frame names _top. it cannot be parent.htm The following example uses string methods to change the size of a string: var worldString="Hello. world" document. HTML syntax To define a form.write("<P>" + worldString.frameName).write(worldString. TARGET="windowName" specifies the window that form responses go to.fontsize(7)) The previous example produces the same output as the following HTML: <SMALL>Hello. When you submit a form with a TARGET attribute. and you can use this name when indexing the forms array. Lets users input text and make choices from Form elements such as checkboxes.big()) document.write("<P>" + worldString. world</SMALL> <P><BIG>Hello. windowName can be an existing window. _parent. world</FONTSIZE> See also big. it can be a frame name specified in a <FRAMESET> tag. small methods Form object Object. it cannot be a JavaScript expression (for example. and selection lists. You can also use a form to post data to a server.

If the METHOD attribute has the value "POST. or Text object) in a form. 4. Property of document Implemented in q q Navigator 2. Radio.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.0 Navigator 3. The elements array contains an entry for each element (such as a Checkbox. Syntax To use a Form object's properties and methods: 1. You can access this value using the action property. methodName is one of the methods listed below.propertyName forms[index]. formName.methodName(parameters) forms[index]. 3. 2. You can reference a form's elements in your code by using the element's name (from the NAME attribute) or the elements array. The forms array file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. If the METHOD attribute has the value "POST.htm CGI or LiveWire application on the server.propertyName formName." then the ENCTYPE attribute typically has the value "application/x-www-form-urlencoded. index is an integer representing a Form object or the name of a Form object as specified by the NAME attribute. ENCTYPE="encodingType" specifies the MIME encoding of the data sent: "application/x-www-form-urlencoded" (the default) or "multipart/form-data. See the location object for a description of the URL components. it can also be a mailto: URL if the form is to be mailed. GET (the default) appends the input information to the URL. added reset method." Use "multipart/form-data" if the form contains a file upload element (INPUT TYPE="file")." You can access this value using the encoding property. which is available on stdin with the data length set in the environment variable CONTENT_LENGTH. added onReset event handler Description Each form in a document is a distinct object. which on most receiving systems becomes the value of the environment variable QUERY_STRING. METHOD=GET | POST specifies how information is sent to the server specified by ACTION.methodName(parameters) Parameters formName is the value of the NAME attribute of a Form object." then the ENCTYPE attribute typically has the value "application/x-www-form-urlencoded.htm (11 of 34) [30/08/2003 9:34:17 PM] ." You can access this value using the method property. POST sends the input information in a data body. propertyName is one of the properties listed below.0: added FileUpload object as property.

quantity. you would refer to a Text object named quantity in the second form as document. You can also refer to a form's elements by using the forms array. document. the statement document.forms.forms[1]. For example. To obtain the number of forms in a document. use the length property: document.forms[index] 2.length.htm You can reference the forms in your code by using the forms array (you can also use the form name).file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.value. and document. where nameAttribute is the NAME attribute of the form. document.forms[0]="music" has no effect. The value of each element in the forms array is <object nameAttribute>. For example. Properties The Form object has the following properties: Property action Description Reflects the ACTION attribute elements array An array reflecting all the elements in a form encoding length name method target Reflects the ENCTYPE attribute Reflects the number of elements on a form Reflects the NAME attribute Reflects the METHOD attribute Reflects the TARGET attribute The following objects are also properties of the Form object: q q q q q q Button Checkbox FileUpload Hidden Password Radio q q q q q Reset object Select object Submit object Text object Textarea The forms array has the following properties: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm (12 of 34) [30/08/2003 9:34:17 PM] .quantity. Elements in the forms array are read-only. This array contains an entry for each Form object (<FORM> tag) in a document in source order. For example. if a document contains three forms.forms[0].forms. these forms are reflected as document.forms[1].forms[2]. You would refer to the value property of this Text object as document. document.forms[1]. To use the forms array: 1.length index is an integer representing a form in a document or the name of a Form object as specified by the NAME attribute.

value=document.value=document.firstName.form1.toLowerCase() document.toUpperCase() document. The following example creates a form called form1 that contains text fields for first name and last name.lastName.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.form1.form1.firstName.form1. The function setCase shows how to refer to the form by its name.value.form1.lastName.value=document.value=document.lastName.value. <HTML> <HEAD> <TITLE>Form object example</TITLE> </HEAD> <SCRIPT> function setCase (caseSpec){ if (caseSpec == "upper") { document.firstName.value.value.form1.form1. The form also contains two buttons that change the names to all uppercase or all lowercase.htm Property Description length Reflects the number of forms in the document Methods The Form object has the following methods: q q q eval method reset method submit method q q toString method valueOf method Event handlers q q onReset onSubmit Examples Example 1: Named form.toLowerCase()} } </SCRIPT> <BODY> <FORM NAME="form1"> <B>First name:</B> <INPUT TYPE="text" NAME="firstName" SIZE=20> <BR><B>Last name:</B> <INPUT TYPE="text" NAME="lastName" SIZE=20> <P><INPUT TYPE="button" VALUE="Names to uppercase" NAME="upperButton" onClick="setCase('upper')"> <INPUT TYPE="button" VALUE="Names to lowercase" NAME="lowerButton" onClick="setCase('lower')"> </FORM> </BODY> </HTML> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.lastName.toUpperCase()} else { document.firstName.htm (13 of 34) [30/08/2003 9:34:17 PM] .form1.

The form uses a button's onClick event handler to call the checkData function. The following example shows an onSubmit event handler that determines whether to submit a form.form1.threeChar. If the value is valid. that returns true if the number of characters is three.length == 3) { return true} else { alert("Enter exactly three characters. The form's onSubmit event handler does not prevent the form from being submitted.threeChar.htm Example 2: forms array. checkData. " + document.value + " is not valid. not the submit button's onClick event handler.") return false} } </SCRIPT> <BODY> <FORM NAME="form1" onSubmit="return checkData()"> <B>Enter 3 characters:</B> <INPUT TYPE="text" NAME="threeChar" SIZE=3> <P><INPUT TYPE="submit" VALUE="Done" NAME="submit1" onClick="document. the onSubmit event handler contains a return statement that returns the value obtained with the function call. the checkData function submits the form by calling the form's submit method. otherwise.threeChar.value=document.value.threeChar. <BODY onLoad="alert('You are looking at the ' + document.form1.form1. The onSubmit event handler calls a function.form1. the alert displays the following message: You are looking at the <object musicType> form! Example 3: onSubmit event handler. calls the checkData function. except it submits the form using the submit method instead of a Submit object. <HTML> <HEAD> <TITLE>Form object/submit method example</TITLE> </HEAD> <SCRIPT> var dataOK=false function checkData (){ file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. it returns false. The form contains one Text object where the user enters three characters.htm (14 of 34) [30/08/2003 9:34:17 PM] .value. The onLoad event handler in the following example displays the name of the first form in an Alert dialog box. Also.forms[0] + ' form!')"> If the form name is musicType. Notice that the form's onSubmit event handler. The following example is similar to the previous one.toUpperCase()"> </FORM> </BODY> </HTML> Example 4: submit method.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. <HTML> <HEAD> <TITLE>Form object/onSubmit event handler example</TITLE> <TITLE>Form object example</TITLE> </HEAD> <SCRIPT> var dataOK=false function checkData (){ if (document.

htm if (document. Reset object.htm (15 of 34) [30/08/2003 9:34:17 PM] .threeChar. Checkbox object.threeChar.submit()} else { alert("Enter exactly three characters. Select object.form1. Submit object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. Hidden object. Hidden object.')"> <B>Enter 3 characters:</B> <INPUT TYPE="text" NAME="threeChar" SIZE=3> <P><INPUT TYPE="button" VALUE="Done" NAME="button1" onClick="checkData()"> </FORM> </BODY> </HTML> See also Button object.form1. form property form property Property.value + " is not valid. " + document.form Parameters objectReference specifies an object on a form.form objectReference. Submit object. Syntax this. Textarea object. Checkbox object. Textarea object Implemented in Navigator 2.0 Tainted? file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. Text object. Reset object. Property of Button object. Password object. Text object.") return false} } </SCRIPT> <BODY> <FORM NAME="form1" onSubmit="alert('Form is being submitted. Radio object. Radio object. An object reference specifying the form containing an object. FileUpload object.value. Select object.length == 3) { document. Password object. FileUpload object.form1.

form)"> </FORM> The alert dialog box displays the following text: JavaScript Alert: Form Elements of form myForm: text1 button1 button2 Example 3. the value of the Text object is set to the form's name. i < theForm.name"> </FORM> Example 2.name + "\n" alert(str) } </script> <FORM NAME="myForm"> Form name:<INPUT TYPE="text" NAME="text1" VALUE="Beluga"> <P> <INPUT NAME="button1" TYPE="button" VALUE="Show Form Name" onClick="this. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. i++) str += theForm. In the following example. myForm.name"> <INPUT NAME="button2" TYPE="button" VALUE="Show Form Elements" onClick="showElements(this.text1.length.form to refer to the parent form.value=this.elements[i]. The button's onClick event handler uses this.value=this. to refer to a form. When the user clicks button2.form. The following example uses an object reference.htm (16 of 34) [30/08/2003 9:34:17 PM] . When the user clicks the button.htm No Description Each form element has a form property that is a reference to the element's parent form. The following example shows a form with several elements. the form myForm contains a Text object and a button. function showElements(theForm) { str = "Form Elements of form " + theForm. This property is especially useful in event handlers. Examples Example 1. the function showElements displays an alert dialog box containing the names of each element on the form myForm.form. which is a form containing myTextObject.name + ": \n " for (i = 0.form. form is a read-only property. where you might need to refer to another element on the current form.form.text1.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. <FORM NAME="myForm"> Form name:<INPUT TYPE="text" NAME="text1" VALUE="Beluga"> <P> <INPUT NAME="button1" TYPE="button" VALUE="Show Form Name" onClick="this. rather than the this keyword. The code returns a reference to myForm.

myForm.0 Description This method performs the same action as a user choosing the Forward button in the Navigator.myTextObject.back()"> <P><INPUT TYPE="button" VALUE="> Forward" file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. An array of objects corresponding to the forms (<FORM> tags) in a document in source order.htm (17 of 34) [30/08/2003 9:34:17 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. Tainted? Yes forward Method. Examples The following custom buttons perform the same operations as the Navigator Back and Forward buttons: <P><INPUT TYPE="button" VALUE="< Back" onClick="history. See the Form object for information.form See also Form object forms Property.go(1).htm document.forward() Method of history object Implemented in Navigator 2. Syntax history. Loads the next URL in the history list. The forward method is the same as history.

<FRAME> defines a frame. independently scrollable frames on a single screen. each with its own distinct URL. [windowReference. all within the same screen. See the location object for a description of the URL components. for example <FRAME SRC="doc2.]frameName. Default units are pixels. An optional suffix defines the units.forward()"> See also back. COLS="columnWidthList" is a comma-separated list of values specifying the column-width of the frame. The URL cannot include an anchor name.html#colors" NAME="frame2"> is invalid. Syntax To use a Frame object's properties: 1.htm onClick="history.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. go methods Frame Object. An optional suffix defines the units. A window that can display multiple.propertyName file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.. and you can use this name when indexing the frames array.htm (18 of 34) [30/08/2003 9:34:17 PM] . Default units are pixels. HTML syntax To define a Frame object. You can access this value using the name property. A series of frames makes up a page. use standard HTML syntax with the addition of JavaScript event handlers: <FRAMESET ROWS="rowHeightList" COLS="columnWidthList" [onBlur="handlerText"] [onFocus="handlerText"] [onLoad="handlerText"] [onUnload="handlerText"]> <FRAME SRC="URL" NAME="frameName"> [ .. NAME="frameName" specifies a name to be used as a target of hyperlink jumps. <FRAME SRC="URL" NAME="frameName">] </FRAMESET> HTML attributes ROWS="rowHeightList" is a comma-separated list of values specifying the row-height of the frame. Frames can point to different URLs and be targeted by other URLs. SRC="URL" specifies the URL of the document to be displayed in the frame.

See the top and parent file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. frameReference. 3. [windowReference. 4.frames[3].propertyName window. frameName is the value of the NAME attribute in the <FRAME> tag of a Frame object.frameName or parent. See the properties listed below for examples. The top and parent properties are also synonyms that can be used in place of the frame name. index is an integer representing a Frame object or the name of a Frame object as specified by the NAME attribute. frameReference. and you can optionally use them to refer to the current frame. propertyName is one of the properties listed below. You can use these properties to make your code more readable.homeFrame or parent.]frames[index]. the name of an error-handling function.htm (19 of 34) [30/08/2003 9:34:17 PM] .0 Navigator 3.0: added blur and focus methods.propertyName parent. Each frame is a window object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. you cannot specify these event handlers in HTML): 1. and parent refers to the window containing the current frameset. If a <FRAME> tag contains SRC and NAME attributes.onblur=errorHandler 2.frames[index]. For example. Implemented in q q Navigator 2. you can refer to that frame from a sibling frame by using parent. The frames array is a property of both the Frame object and window object. or one of the synonyms top or parent. 5. if the fourth frame in a set has NAME="homeFrame." sibling frames can refer to that frame using parent. frameReference is a valid way of referring to a frame.propertyName self. errorHandler is the keyword null. The self and window properties are synonyms for the current frame.onfocus=errorHandler Parameters windowReference is a variable windowVar from a window definition (see the window object). Property of The Frame object is a property of the window object. or a variable or property that contains null or a valid function reference.propertyName To define an onBlur or onFocus event handler for a frame (for frames. top refers to the top-most window that contains frames or nested framesets.htm 2. added onBlur and onFocus event handlers Description The <FRAMESET> tag is used in an HTML document whose sole purpose is to define the layout of frames that make up a page.

length frameReference is a valid way of referring to a frame. To create an onBlur or onFocus event handler for a frame. index is an integer representing a frame in a parent window or the name of a Frame object as specified by the NAME attribute.]frames.frames[0].length [frameReference. where nameAttribute is the NAME attribute of the frame. To obtain the number of child frames in a window or frame. For example. you must set the onblur or onfocus property and specify it in all lowercase (you cannot specify it in HTML).].length [windowReference.frames[1]. For example. 2. To use the frames array: 1. The frames array You can reference the Frame objects in your code by using the frames array.frames[0]="frame1" has no effect. This array contains an entry for each child frame (<FRAME> tag) in a window containing a <FRAMESET> tag in source order.]frames.]frames[index] [frameReference. if a window contains three child frames. The value of each element in the frames array is <object nameAttribute>.length Elements in the frames array are read-only. these frames are reflected as parent. the statement windowReference.htm (20 of 34) [30/08/2003 9:34:17 PM] .].frames.frames.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. 3. use the length property: [windowReference.]frames[index] [windowReference. 4. [frameReference.htm properties. Properties The Frame object has the following properties: Property frames name length parent self Description An array reflecting all the frames in a window Reflects the NAME attribute of the <FRAME> tag Reflects the number of child frames within a frame A synonym for the window or frame containing the current frameset A synonym for the current frame window property A synonym for the current frame The frames array has the following properties: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. parent. and parent. windowReference is a variable windowVar from a window definition (see the window object).frames[2]. or one of the synonyms top or parent.

html.html NAME="frame3"> <FRAME SRC=framcon2. In the first window. which defines the frames for the first window. Examples The following example creates two windows.html NAME="frame1"> <FRAME SRC=framcon2.html NAME="frame4"> </FRAMESET> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.html NAME="frame1"> <FRAME SRC=framcon2. each with four frames.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.50%" COLS="40%. contains the following code: <HTML> <HEAD> <TITLE>Frames and Framesets: Window 2</TITLE> </HEAD> <FRAMESET ROWS="50%. the first frame contains pushbuttons that change the background colors of the frames in both windows.html NAME="frame3"> <FRAME SRC=framcon2. which defines the frames for the second window.html NAME="frame2"> <FRAME SRC=framcon2.htm (21 of 34) [30/08/2003 9:34:17 PM] .htm Property Description length Reflects the number of child frames in the document Methods The Frame object has the following methods: q q q q blur clearTimeout eval focus q q q setTimeout toString valueOf Event handlers q q onBlur onFocus The onLoad and onUnload event handlers are specified in the <FRAMESET> tag but are actually event handlers for the window object.html NAME="frame2"> <FRAME SRC=framcon2. World.html NAME="frame4"> </FRAMESET> </HTML> framset2. framset1.')"> <FRAME SRC=framcon1. contains the following code: <HTML> <HEAD> <TITLE>Frames and Framesets: Window 1</TITLE> </HEAD> <FRAMESET ROWS="50%.50%" COLS="40%.60%" onLoad="alert('Hello.60%"> <FRAME SRC=framcon2.html.

frame3 to fuchsia" onClick="window2. contains the following code: <HTML> <BODY> <P>This is a frame.bgColor='fuchsia'"> <P><INPUT TYPE="button" VALUE="window2. window object frames file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm" target=frame2>Click here</A> to load a different file into frame 2.htm </HTML> framcon1.document.htm". contains the following code: <HTML> <BODY> <P>This is a frame. <SCRIPT> window2=open("framset2.document.frame2.document.html. which defines the content for the first frame in the first window.frame4 to deeppink" onClick="window2.frames[3]."secondFrameset") </SCRIPT> <FORM> <P><INPUT TYPE="button" VALUE="Change frame2 to teal" onClick="parent. which defines the content for the remaining frames.bgColor='violet'"> <P><INPUT TYPE="button" VALUE="window2.html.bgColor='slateblue'"> <P><INPUT TYPE="button" VALUE="Change frame4 to darkturquoise" onClick="top.frames[3]. contains the following code: <HTML> <BODY> <A NAME="frame1"><H1>Frame1</H1></A> <P><A HREF="framcon3.bgColor='darkturquoise'"> <P><INPUT TYPE="button" VALUE="window2.frame2.htm (22 of 34) [30/08/2003 9:34:17 PM] . What do you think? </BODY> </HTML> See also document object. which is referenced in a Link object in framcon1.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.frames[2].document.frame2 to violet" onClick="window2.html.html.frames[2].document.bgColor='deeppink'"> </FORM> </BODY> </HTML> framcon2. </BODY> </HTML> framcon3.document.bgColor='teal'"> <P><INPUT TYPE="button" VALUE="Change frame3 to slateblue" onClick="parent.

Syntax To create a Function object: functionObjectName = new Function ([arg1.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.. propertyName is one of the properties listed below.htm (23 of 34) [30/08/2003 9:34:17 PM] . arg2.htm Property.. arg2. functionObjectName is either the name of an existing Function object or a property of an existing object. Tainted? No Function Object. .propertyName Parameters functionObjectName is the name of a variable or a property of an existing object. because declared functions are compiled.. arg1. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. argn]. functionBody is a string specifying the JavaScript code to be compiled as the function body.0 Description Function objects are evaluated each time they are used. Property of None Implemented in Navigator 3. Each must be a string that corresponds to a valid JavaScript identifier. Specifies a string of JavaScript code to be compiled as a function. It can also be an object followed by a lowercase event handler name. for example "x" or "theForm". such as window. This is less efficient than declaring a function and calling it within your code.onerror. . An array of objects corresponding to child frames (<FRAME> tag) in source order. When using Function properties. See the Frame object for information. functionBody) To use a Function object: functionObjectName.. argn are arguments to be used by the function as formal argument names.

document.operand1. as described in "function".. you can also use the function statement. you can specify the variable name as if it were a function. it is the name of a function.. "y". "return x * y") The string arguments "x" and "y" are formal argument names that are used in the function body.onclick=setBGColor 2. "return x * y".}.6) document.result.").form1.write("15*2 = " + multFun(15.htm (24 of 34) [30/08/2003 9:34:17 PM] . Specifying a variable value with a Function object The following code assigns a function to the variable setBGColor. setBGColor is not a variable. <INPUT NAME="colorButton" TYPE="button" VALUE="Change background color" onClick="setBGColor()"> Creating the variable setBGColor shown above is similar to declaring the following function: function setBGColor() { document.form1. but they have differences: q q When you assign a function to a variable using var setBGColor = new Function(".value.value= multFun(document. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.. The following code executes the function specified by the setBGColor variable: var colorChoice="antiquewhite" if (colorChoice=="antiquewhite") {setBGColor()} You can assign the function to an event handler in either of the following ways: 1. Specifying arguments in a Function object The following code specifies a Function object that takes two arguments. This function sets the current document's background color..bgColor='antiquewhite'") To call the Function object.colorButton. The following code shows several ways to call the function multFun: var theAnswer = multFun(7. When you create a function using function setBGColor() {. var multFun = new Function("x".file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.2)) <INPUT NAME="operand1" TYPE="text" VALUE="5" SIZE=5> <INPUT NAME="operand2" TYPE="text" VALUE="6" SIZE=5> <INPUT NAME="result" TYPE="text" VALUE="" SIZE=10> <INPUT NAME="buttonM" TYPE="button" VALUE="Multiply" onClick="document.bgColor='antiquewhite' } Assigning a function to a variable is similar to declaring a function.htm In addition to defining functions as described here. var setBGColor = new Function("document. setBGColor is a variable for which the current value is a reference to the function created with new Function().form1.

operand2.bgColor='lightgrey'") Example 2. You can determine whether a function exists by comparing the function name to null.onfocus = new Function("document.htm (25 of 34) [30/08/2003 9:34:17 PM] . For example.button1. Methods q q q eval toString valueOf Event handlers None. because you cannot specify the event handlers in the <FRAME> tag.onblur = new Function("document.10) Specifying an event handler with a Function object The following code assigns a function to a window's onFocus event handler (the event handler must be spelled in all lowercase): window. Note that this is the only way to create onFocus and onBlur event handlers for a frame. you can use it like a function and it will convert from an object to a function: window.form1. you cannot call the function multFun by setting a button's onclick property as follows: document. so you cannot declare any arguments in the Function() constructor for an event handler. because event handler properties cannot take arguments.form1. In the following example.bgColor='antiquewhite'") frames[0].file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. Examples Example 1.bgColor='antiquewhite'") Once you have a reference to a function object.onclick=multFun(5. Properties The Function object has the following properties: Property caller prototype Description Specifies which function called the current function Lets you add a properties to a Function object. frames[0]. arguments array Corresponds to elements of a function.htm document. Notice that the window name is needed when referring to the file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. The following example creates onFocus and onBlur event handlers for a frame.onfocus = new Function("document. otherwise func2 is called. This code exists in the same file that contains the <FRAMESET> tag. func1 is called if the function noFunc does not exist.value)"> You cannot call the function multFun in an object's event handler property.onfocus() Event handlers do not take arguments.

1995 23:15:00") day = Xmas95. Xmas95 = new Date("December 25.getDate() See also setDate method getDay file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. based on the value of the Date object Xmas95. if (window.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.getDate() Parameters dateObjectName is either the name of a Date object or a property of an existing object.0 Description The value returned by getDate is an integer between one and 31. Syntax dateObjectName. Method of Date Implemented in Navigator 2.htm function name noFunc.htm (26 of 34) [30/08/2003 9:34:17 PM] .noFunc == null) func1() else func2() getDate Method. Returns the day of the month for the specified date. Examples The second statement below assigns the value 25 to the variable day.

is a Monday.htm (27 of 34) [30/08/2003 9:34:17 PM] . Method of Date file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. Returns the day of the week for the specified date. two for Tuesday. Method of Date Implemented in Navigator 2. 1995 23:15:00") weekday = Xmas95. Syntax dateObjectName.getHours() Parameters dateObjectName is either the name of a Date object or a property of an existing object. Syntax dateObjectName.getDay() getHours Method. one for Monday.htm Method. based on the value of the Date object Xmas95. Returns the hour for the specified date. 1995. This is because December 25. and so on.0 Description The value returned by getDay is an integer corresponding to the day of the week: zero for Sunday. Xmas95 = new Date("December 25.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. Examples The second statement below assigns the value 1 to weekday.getDay() Parameters dateObjectName is either the name of a Date object or a property of an existing object.

based on the value of the Date object Xmas95.htm Implemented in Navigator 2.0 Description The value returned by getHours is an integer between zero and 23. Returns the minutes in the specified date.htm (28 of 34) [30/08/2003 9:34:17 PM] . Xmas95 = new Date("December 25. Examples file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g. Examples The second statement below assigns the value 23 to the variable hours. 1995 23:15:00") hours = Xmas95. Method of Date Implemented in Navigator 2.getHours() See also setHours method getMinutes Method.0 Description The value returned by getMinutes is an integer between zero and 59. Syntax dateObjectName.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.getMinutes() Parameters dateObjectName is either the name of a Date object or a property of an existing object.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm

The second statement below assigns the value 15 to the variable minutes, based on the value of the Date object Xmas95. Xmas95 = new Date("December 25, 1995 23:15:00") minutes = Xmas95.getMinutes()

See also
setMinutes method

getMonth
Method. Returns the month in the specified date.

Syntax
dateObjectName.getMonth()

Parameters
dateObjectName is either the name of a Date object or a property of an existing object.

Method of
Date

Implemented in
Navigator 2.0

Description
The value returned by getMonth is an integer between zero and 11. Zero corresponds to January, one to February, and so on.

Examples
The second statement below assigns the value 11 to the variable month, based on the value of the Date object Xmas95. Xmas95 = new Date("December 25, 1995 23:15:00") month = Xmas95.getDate()

See also
setMonth method

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm (29 of 34) [30/08/2003 9:34:17 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm

getSeconds
Method. Returns the seconds in the current time.

Syntax
dateObjectName.getSeconds()

Parameters
dateObjectName is either the name of a Date object or a property of an existing object.

Method of
Date

Implemented in
Navigator 2.0

Description
The value returned by getSeconds is an integer between zero and 59.

Examples
The second statement below assigns the value 30 to the variable secs, based on the value of the Date object Xmas95. Xmas95 = new Date("December 25, 1995 23:15:30") secs = Xmas95.getSeconds()

See also
setSeconds method

getTime
Method. Returns the numeric value corresponding to the time for the specified date.

Syntax
dateObjectName.getTime()

Parameters
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm (30 of 34) [30/08/2003 9:34:17 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm

dateObjectName is either the name of a Date object or a property of an existing object.

Method of
Date

Implemented in
Navigator 2.0

Description
The value returned by the getTime method is the number of milliseconds since 1 January 1970 00:00:00. You can use this method to help assign a date and time to another Date object.

Examples
The following example assigns the date value of theBigDay to sameAsBigDay: theBigDay = new Date("July 1, 1999") sameAsBigDay = new Date() sameAsBigDay.setTime(theBigDay.getTime())

See also
setTime method

getTimezoneOffset
Method. Returns the time-zone offset in minutes for the current locale.

Syntax
dateObjectName.getTimezoneOffset()

Parameters
dateObjectName is either the name of a Date object or a property of an existing object.

Method of
Date

Implemented in

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm (31 of 34) [30/08/2003 9:34:17 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm

Navigator 2.0

Description
The time-zone offset is the difference between local time and GMT. Daylight savings time prevents this value from being a constant.

Examples
x = new Date() currentTimeZoneOffsetInHours = x.getTimezoneOffset()/60

getYear
Method. Returns the year in the specified date.

Syntax
dateObjectName.getYear()

Parameters
dateObjectName is either the name of a Date object or a property of an existing object.

Method of
Date

Implemented in
Navigator 2.0

Description
The getYear method returns either a two-digit or four-digit year:
q

q

For years prior to 2000, the value returned by getYear is the year less 1900. For example, if the year is 1976, the value returned is 76. For the years 2000 and beyond, the value returned by getYear is the four-digit year. For example, if the year is 2026, the value returned is 2026.

Examples
Example 1. The second statement below assigns the value 95 to the variable year, based on the value of the Date object Xmas95. Xmas95 = new Date("December 25, 1995 23:15:00") year = Xmas95.getYear()

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm (32 of 34) [30/08/2003 9:34:17 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm

Example 2. The second statement below assigns the value 2026 to the variable theYear, based on the value of the Date object newYears2026. newYears2026 = new Date("2026, January, 1") theYear = newYears2026.getYear()

See also
setYear method

go
Method. Loads a URL from the history list.

Syntax
history.go(delta | "location")

Parameters
delta is an integer or a property of an existing object, representing a relative position in the history list. location is a string or a property of an existing object, representing all or part of a URL in the history list.

Method of
history object

Implemented in
Navigator 2.0

Description
The go method navigates to the location in the history list determined by the argument that you specify. You can interactively display the history list by choosing History from the Window menu. Up to 10 items in the history list are also displayed on the Go menu. The delta argument is a positive or negative integer. If delta is greater than zero, the go method loads the URL that is that number of entries forward in the history list; otherwise, it loads the URL that is that number of entries backward in the history list. If delta is zero, Navigator reloads the current page. The location argument is a string. Use location to load the nearest history entry whose URL contains location as a substring. The location to URL matching is case-insensitive. Each section of a URL contains different information. See the location object for a description of the URL components.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm (33 of 34) [30/08/2003 9:34:17 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm

The go method creates a new entry in the history list. To load a URL without creating an entry in the history list, use replace.

Examples
The following button navigates to the nearest history entry that contains the string "home.netscape.com": <P><INPUT TYPE="button" VALUE="Go" onClick="history.go('home.netscape.com')"> The following button navigates to the URL that is three entries backward in the history list: <P><INPUT TYPE="button" VALUE="Go" onClick="history.go(-3)">

See also
back, forward, reload, replace methods

[Next reference file]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_f-g.htm (34 of 34) [30/08/2003 9:34:17 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

[Previous reference file]

hash
Property. A string beginning with a hash mark (#) that specifies an anchor name in the URL.

Syntax
1. links[index].hash 2. location.hash 3. areaName.hash

Parameters
index is an integer representing a Link object or the name of a Link object as specified by the NAME attribute. areaName is the value of the NAME attribute of an Area object.

Property of
Area object (see Link object), Link object, location object

Implemented in
q q

Navigator 2.0 Navigator 3.0: property of Area

Tainted?
Yes

Description
The hash property specifies a portion of the URL. This property applies to http URLs only. You can set the hash property at any time, although it is safer to set the href property to change a location. If the hash that you specify cannot be found in the current location, you will get an error. Setting the hash property navigates to the named anchor without reloading the document. This differs from the way a document is loaded when other location properties are set (see "How documents are loaded when location is set"). In event handlers, you must specify window.location.hash instead of simply using location.hash. Due to the scoping of static objects in JavaScript, a call to location without specifying an object name is equivalent to document.location, which is a synonym for document.URL.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (1 of 49) [30/08/2003 9:34:21 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

See RFC 1738 for complete information about the hash.

Examples
See the examples for the Anchor object and the href property.

See also
host, hostname, href, pathname, port, protocol, search properties

height
Property. A string specifying the height of an image in pixels.

Syntax
imageName.height

Parameters
imageName is either the name of an Image object or an element in the images array.

Property of
Image

Implemented in
Navigator 3.0

Tainted?
No

Description
The height property reflects the HEIGHT attribute of the <IMG> tag. For images created with the Image() constructor, the value of the height property is the actual, not the displayed, height of the image. height is a read-only property.

Examples

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (2 of 49) [30/08/2003 9:34:21 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

The following function displays the values of an image's height, width, hspace, and vspace properties. function showImageSize(theImage) { alert('height=' + theImage.height+ '; width=' + theImage.width + '; hspace=' + theImage.hspace + '; vspace=' + theImage.vspace) }

See also
border, hspace, vspace, width properties

Hidden
Object. A Text object that is suppressed from form display on an HTML form. A Hidden object is used for passing name/value pairs when a form submits.

HTML syntax
To define a Hidden object, use standard HTML syntax: <INPUT TYPE="hidden" NAME="hiddenName" [VALUE="textValue"]>

HTML attributes
NAME="hiddenName" specifies the name of the Hidden object. You can access this value using the name property, and you can use this name when indexing the elements array. VALUE="textValue" specifies the initial value of the Hidden object.

Syntax
To use a Hidden object's properties: 1. hiddenName.propertyName 2. formName.elements[index].propertyName

Parameters
hiddenName is the value of the NAME attribute of a Hidden object.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (3 of 49) [30/08/2003 9:34:21 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

formName is either the value of the NAME attribute of a Form object or an element in the forms array. index is an integer representing a Hidden object on a form or the name of a Hidden object as specified by the NAME attribute. propertyName is one of the properties listed below.

Property of
Form object

Implemented in
q q

Navigator 2.0 Navigator 3.0: added type property

Description
A Hidden object is a form element and must be defined within a <FORM> tag. A Hidden object cannot be seen or modified by a user, but you can programmatically change the value of the object by changing its value property. You can use Hidden objects for client/server communication.

Properties
The Hidden object has the following properties:

Property name

Description Reflects the NAME attribute

form property Specifies the form containing the Hidden object type value Reflects the TYPE attribute Reflects the current value of the Hidden object

Methods
q q q

eval toString valueOf

Event handlers
None.

Examples
The following example uses a Hidden object to store the value of the last object the user clicked. The form contains a "Display
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (4 of 49) [30/08/2003 9:34:21 PM]

value)"> </FORM> </BODY> </HTML> See also cookie property history array Property.form1.hiddenObject.value=this. An array reflecting all the history entries in a window in source order.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.value=this.text"> <OPTION SELECTED> Red <OPTION> Orange <OPTION> Yellow </SELECT> <P><INPUT TYPE="button" VALUE="Display hidden value" NAME="button2" onClick="alert('Last object clicked: ' + document. See the history object for information.value=this.value"> Soul and R&B <INPUT TYPE="radio" NAME="musicChoice" VALUE="jazz" onClick="document.htm hidden value" button that the user can click to display the value of the Hidden object in an Alert dialog box. <HTML> <HEAD> <TITLE>Hidden object example</TITLE> </HEAD> <BODY> <B>Click some of these objects.hiddenObject.</B> <FORM NAME="form1"> <INPUT TYPE="hidden" NAME="hiddenObject" VALUE="None"> <P> <INPUT TYPE="button" VALUE="Click me" NAME="button1" onClick="document.form1.value=this.selectedIndex].value"> Classical <P> <SELECT NAME="music_type_single" onFocus="document.value=this.form1.hiddenObject.htm (5 of 49) [30/08/2003 9:34:21 PM] .form1.hiddenObject.form1.value"> <P> <INPUT TYPE="radio" NAME="musicChoice" VALUE="soul-and-r&b" onClick="document.form1. then click the "Display value" button <BR>to see the value of the last object clicked. Tainted? No file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.hiddenObject.value"> Jazz <INPUT TYPE="radio" NAME="musicChoice" VALUE="classical" onClick="document.hiddenObject.options[this.

history. history. windowReference is a valid way of referring to a window. This information is stored in a history list and is accessible through the Navigator Go menu. these entries are reflected as history[0].propertyName 2. you can use the replace method. To use the history array: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. Contains information on the URLs that the client has visited within a window. Property of window object Implemented in q q Navigator 2. index is an integer representing an entry in the history list. Syntax To use a history object: 1.htm history object Object. history[1]. To change a window's current URL without generating a history entry.0 Navigator 3. methodName is one of the methods listed below. next. and history[2]. See the replace method. each array entry is a string containing a URL.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. added history array Description The history object is a linked list of URLs the user has visited. This replaces the current page with a new one without generating a history entry. For example.htm (6 of 49) [30/08/2003 9:34:21 PM] . The history array You can reference the history entries by using the history array. [windowReference. as described in the window object. as shown in the Navigator Go menu.0: added current.methodName(parameters) 3.]history[index] Parameters propertyName is one of the properties listed below. and previous properties. if the history list contains three named entries. This array contains an entry for each history entry in source order.

htm 1.netscape. Navigator returns a string of HTML which displays a table of URLs. To obtain the number of entries in the history list. If you access the history array without specifying an array element. history. history[index] 2.htm (7 of 49) [30/08/2003 9:34:21 PM] . the statement history[0]="http://home.length index is an integer representing an entry in the history list. Examples Example 1. use the length property: history. The following example goes to the URL the user visited three clicks ago in the current window.length.com" has no effect.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. history. Elements in the history array are read-only. Properties The history object has the following properties: Property Description current length next Specifies the URL of the current history entry Reflects the number of entries in the history list Specifies the URL of the next history entry previous Specifies the URL of the previous history entry The history array has the following properties: Property Description length Reflects the number of history entries in the window Methods The History object has the following methods: q q q back eval forward q q q go toString valueOf Event handlers None.go(-3) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. each of which is a hyperlink. For example.

frames[1]. If it does. replace method host file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. The following example causes window2 to go back one item in its window (or session) history: window2.com/ http://sapphire. The following example causes the frame named frame1 in a frameset to go back one item: parent.back() Example 6.cse. You can use the history object with a specific window or frame.indexOf("NETSCAPE") != -1) { myFunction(history[0]) } Example 7.ucsc.history.sun.history. if (history[0].htm (8 of 49) [30/08/2003 9:34:21 PM] .back() Example 3.net/~dugbrown/ See also location object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. The following example displays the entire history list: document. The following example causes the frame named frame2 in window2 to go back one item: window2.back() Example 4.edu/SlugVideo/dream-inn.history. The following example causes the second frame in a frameset to go back one item: parent.com/ http://www.netscape.htm Example 2.back() Example 5. The following code determines whether the first entry in the history array contains the string "NETSCAPE".history.frame1.writeln("<B>history is</B> " + history) This code displays output similar to the following: history is Welcome to Netscape Sun Microsystems SlugVideo at the Dream Inn Bad Dog Chronicles http://home. the function myFunction is called.html http://www.frame2.supernet.

areaName. Property of Area object (see Link object). In event handlers. Examples See the examples for the href property.0: property of Area Tainted? Yes Description The host property specifies a portion of a URL.0 Navigator 3. The hostname property is the concatenation of the host and port properties. Link object. See Section 3.host 2. and domain name.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. location. If the host that you specify cannot be found in the current location.htm Property. separated by a colon. a call to location without specifying an object name is equivalent to document. subdomain. although it is safer to set the href property to change a location. A string specifying the server name.location.host 3.htm (9 of 49) [30/08/2003 9:34:21 PM] . Syntax 1. the host property is the same as the hostname property. you must specify window.host instead of simply using location. which is a synonym for document.1 of RFC 1738 for complete information about the hostname and port. When the port property is null.host. The host property is a substring of the hostname property. you will get an error. areaName is the value of the NAME attribute of an Area object. See also file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. You can set the host property at any time.location.host Parameters index is an integer representing a Link object or the name of a Link object as specified by the NAME attribute. links[index]. location object Implemented in q q Navigator 2.URL. Due to the scoping of static objects in JavaScript.

hostname 3. Property of Area object (see Link object). search properties hostname Property. you must specify window. Syntax 1. protocol.htm (10 of 49) [30/08/2003 9:34:21 PM] . Due to the scoping of static objects in JavaScript.hostname Parameters index is an integer representing a Link object or the name of a Link object as specified by the NAME attribute. Link object. including the server name.hostname. If the hostname that you specify cannot be found in the current location. A string containing the full hostname of the server.htm hash.location. which is a synonym for document.hostname instead of simply using location. links[index]. subdomain. domain.0 Navigator 3.hostname 2. the host property is the same as the hostname property. In event handlers.0: property of Area Tainted? Yes Description The hostname property specifies a portion of a URL. a call to location without specifying an object name is equivalent to document. areaName is the value of the NAME attribute of an Area object.location.URL. you will get an error. When the port property is 80 (the default). href. separated by a colon. port. You can set the hostname property at any time. pathname. location object Implemented in q q Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. areaName. and port number. hostname. although it is safer to set the href property to change a location. location. The hostname property is the concatenation of the host and port properties. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.

Property of Area object (see Link object).htm (11 of 49) [30/08/2003 9:34:21 PM] . location object Implemented in q q Navigator 2. areaName.href 2.href Parameters index is an integer representing a Link object or the name of a Link object as specified by the NAME attribute. See also hash.0: property of Area Tainted? Yes Description The href property specifies the entire URL. Link object. search properties href Property. links[index].1 of RFC 1738 for complete information about the hostname.href 3. pathname.0 Navigator 3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. areaName is the value of the NAME attribute of an Area object. port. Examples See the examples for the href property. protocol. location. Other location object properties are substrings of the href property. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm See Section 3. host. Syntax 1. A string specifying the entire URL. href.

com/" window.document.netscape.location.location.document.netscape. Omitting a property name from the location object is equivalent to specifying location.location.write("newWindow.com/comprod/products/navigator/ version_2.netscape. newWindow=window.location.write("newWindow.pathname = " + newWindow.location.location in a window called msgWindow.com newWindow.com newWindow.location.write("newWindow.com/" In event handlers.port = " + newWindow.location.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.href.hostName = home.pathname + "<P>") msgWindow.location.search + "<P>") msgWindow.hostName = " + newWindow.port + "<P>") msgWindow.location. a call to location without specifying an object name is equivalent to document. which is a synonym for document.location.location.host + "<P>") msgWindow.hash + "<P>") msgWindow.href.html#checkbox_object") msgWindow.search = " + newWindow. you must specify window. the window.netscape.location.write("newWindow. See RFC 1738 for complete information about the URL.document.href = " + newWindow.URL.html#checkbox_object newWindow. the following two statements are equivalent and set the URL of the current window to the Netscape home page: window.document.protocol = " + newWindow.protocol = http: newWindow.open statement creates a window called newWindow and loads the specified URL into it.com/comprod/products/navigator/ version_2.close() The previous example displays output such as the following: newWindow.location.location.hostName + "<P>") msgWindow.href instead of simply using location.0/script/script_info/objects.host = home. Due to the scoping of static objects in JavaScript.write("newWindow.location.open ("http://home.location.htm You can set the href property at any time.host = " + newWindow.location.location.location="http://home.netscape.netscape. Examples In the following example.hash = " + newWindow.write("newWindow. For example.document.protocol + "<P>") msgWindow.location.port = file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.href = http://home.location. The document.href="http://home.htm (12 of 49) [30/08/2003 9:34:21 PM] .location.document.write statements display all the properties of newWindow.location.location.location.document.write("newWindow.0/script/script_info/objects.href + "<P>") msgWindow.write("newWindow.document.document.

Syntax imageName.htm (13 of 49) [30/08/2003 9:34:21 PM] . pathname. Examples See the examples for the height property.html newWindow. Property of Image Implemented in Navigator 3.hash = #checkbox_object newWindow.hspace Parameters imageName is either the name of an Image object or an element in the images array. the value of the hspace property is 0.location. For images created with the Image() constructor.location. hostname.search = See also hash.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. port.0 Tainted? No Description The hspace property reflects the HSPACE attribute of the <IMG> tag. host. protocol.htm newWindow.0/script/ script_info/objects. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. A string specifying a margin in pixels between the left and right edges of an image and the surrounding text. hspace is a read-only property.location. search properties hspace Property.pathname = /comprod/products/navigator/version_2.

An image on an HTML form. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. HEIGHT="Pixels"|"Value"% specifies the height of the image either in pixels or as a percentage of the window height.htm See also border. height. SRC="Location" specifies the URL of the image to be displayed in the document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. HTML syntax To define an image. Navigator loads this smaller image and then replaces it with the larger image specified by SRC. Navigator scales the image to fit the space specified by this attribute. and you can use this name when indexing the images array. You can access this value using the src property. If necessary. width properties Image Object. You can access this value using the lowsrc property. use standard HTML syntax with the addition of JavaScript event handlers: <IMG [NAME="imageName"] SRC="Location" [LOWSRC="Location"] [HEIGHT="Pixels"|"Value"%] [WIDTH="Pixels"|"Value"%] [HSPACE="Pixels"] [VSPACE="Pixels"] [BORDER="Pixels"] [ALIGN="left"|"right"| "top"|"absmiddle"|"absbottom"| "texttop"|"middle"|"baseline"|"bottom"] [ISMAP] [USEMAP="#MapName"] [onAbort="handlerText"] [onError="handlerText"] [onLoad="handlerText"]> HTML attributes NAME="imageName" specifies the name of the Image object. vspace. You can access this value using the name property. LOWSRC="Location" specifies the URL of a low-resolution version of the image to be displayed in the document. You can access this value using the height property.htm (14 of 49) [30/08/2003 9:34:21 PM] .

htm (15 of 49) [30/08/2003 9:34:21 PM] . When using an Image object's properties. imageName. USEMAP="#MapName" specifies the image as a client-side image map.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. if you suppress the border of an image that appears within an anchor. ALIGN specifies the alignment of the image in relation to the surrounding text. in pixels. If necessary. imageName. document. This attribute applies only to images that use "left" or "right" as the value of the ALIGN attribute. If omitted. Images that are aligned as "left" or "right" float into the next available space on the left or right side of the page. users will not see a colored border indicating that the image is a hyperlink. You can access this value using the hspace property.htm WIDTH="Pixels"|"Value"% specifies the width of the image either in pixels or as a percentage of the window width. Syntax To create an Image object: imageName = new Image([width. HSPACE="Pixels" specifies a margin in pixels between the left and right edges of the image and the surrounding text. You can access this value using the vspace property. USEMAP="#areamap". For example. width is the image width. "bottom" is used. however. imageName is the value of the NAME attribute of an Image object or the imageName specified with the Image() constructor. imageName. formName.onabort = handlerFunction 2. and cause text to wrap around them. VSPACE="Pixels" specifies a margin in pixels between the top and bottom edges of the image and the surrounding text. of an image border. Other ALIGN values place the image in a line of text and do not cause the text to wrap. Navigator scales the image to fit the space specified by this attribute. You can access this value using the width property. in pixels.propertyName 2. This attribute specifies the # symbol followed by the name of the map. You can access this value using the border property. height]) To use an Image object's properties: 1.elements[index].onload = handlerFunction Parameters imageName is either the name of a new object or a property of an existing object. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. This attribute applies only to images that use "left" or "right" as the value of the ALIGN attribute.onerror = handlerFunction 3.propertyName 3. ISMAP specifies the image as a server-side image map. You can suppress the border by setting its value to 0. imageName.propertyName To define an event handler for an Image object created with the Image() constructor: 1.images[index]. BORDER="Pixels" specifies the width.

or you could display one file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. You can change which image is displayed by setting the src and lowsrc properties.src = "seaotter. you can use the Area or Link object's event handlers. onMouseOut. handlerFunction is the keyword null.htm height is the image height. you can set the src property of the displayed image to the same value as that used for the prefetched image. rather than loaded over the network. Image objects do not have onClick.0 Description The position and size of an image in a document are set when the document is displayed in Navigator and cannot be changed using JavaScript (the width and height properties are read-only). when used with the elements array. as shown in Example 4 below. However. propertyName is one of the properties listed below. assuming that sufficient time has elapsed to load and decode the entire image. index..file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.gif" . each frame is in a separate file. with JavaScript animation. if you define an Area object for the image or place the <IMG> tag within a Link object. See the Link object. document. formName is either the value of the NAME attribute of a Form object or an element in the forms array. in pixels. JavaScript animation is slower than GIF animation. (See the descriptions of src and lowsrc. index.src The resulting image will be obtained from cache. the name of a function.. is an integer representing an Image object on a form.src = myImage. myImage = new Image() myImage. Property of document Implemented in Navigator 3. or a variable or property that contains null or a valid function reference. The Image() constructor The primary use for an Image object created with the Image() constructor is to load an image from the network (and decode it) before it is actually needed for display. Then when you need to display the image within an existing image cell. as follows. You can use this technique to create smooth animations. because with GIF animation the entire animation is in one file. and onMouseOver event handlers. and each file must be loaded across the network (host contacted and data transferred).htm (16 of 49) [30/08/2003 9:34:21 PM] .) You can use JavaScript to create an animation with an Image object by repeatedly setting the src property. when used with the images array is an integer representing an Image object or the name of an Image object as specified by the NAME attribute.images[0].

images[2]. and vspace properties are not meaningful for images created with the Image() constructor. This array contains an entry for each Image object (<IMG> tag) in a document in source order (images created with the Image() constructor are not included in the images array).gif" has no effect.htm of several images based on form input. For example. and document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. document. document. Elements in the images array are read-only. src vspace width Reflects the SRC attribute Reflects the VSPACE attribute Reflects the WIDTH attribute Note The border.length. Properties The Image object has the following properties: Property Description border Reflects the BORDER attribute complete Boolean value indicating whether Navigator has completed its attempt to load the image height hspace lowsrc name Reflects the HEIGHT attribute Reflects the HSPACE attribute Reflects the LOWSRC attribute Reflects the NAME attribute prototype Lets you add a properties to an Image object. the statement document. To obtain the number of images in a document. these images are reflected as document.images[1].images.length index is an integer representing an image in a document or the name of an Image object as specified by the NAME attribute.images[index] 2. For example. hspace. The images array You can reference the images in a document by using the images array. The images array has the following properties: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.images[0]="logo. name. if a document contains three images.images[0]. use the length property: document.htm (17 of 49) [30/08/2003 9:34:21 PM] . To use the images array: 1. document.images.

When the user clicks the button to order the shirt. The image displayed depends on the shirt color and size that the user chooses. the user selects which image is displayed. myImage is created with dimensions equal to that of the image named in the source URL.src='f15e.src='f15e.gif' When you refer to an image by its name.gif" Example 3: Display an image based on form input.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.src = "seaotter.myForm. it is scaled to that size.gif" ALIGN="left" VSPACE="10"> The following code refers to the image: document. The user orders a shirt by filling out a form.htm (18 of 49) [30/08/2003 9:34:21 PM] . The following code refers to the image if it is on a form: document. that is 70 pixels wide and 50 pixels high. 50) myImage.src = "seaotter.aircraft. myImage = new Image(70. myImage = new Image() myImage.htm Property Description length Reflects the number of images in a document Methods q q q eval toString valueOf Event handlers q q q onAbort onError onLoad Examples Example 1: Create an image with the <IMG> tag. The following code defines an image using the <IMB> tag: <IMG NAME="aircraft" SRC="f15e.gif" If you omit the width and height arguments from the Image() constructor. seaotter. All possible image choices are pre-loaded to speed response time. myImage. If the source URL.gif' Example 2: Create an image with the Image() constructor. does not have dimensions of 70x50 pixels. The following example creates an Image object. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. the allShirts function displays the images of all the shirts.gif.aircraft. you must include the form name if the image is on a form. In the following example.

charAt(0) + "-" + shirtSize.htm <SCRIPT> shirts = new Array() shirts[0] = "R-S" shirts[1] = "R-M" shirts[2] = "R-L" shirts[3] = "W-S" shirts[4] = "W-M" shirts[5] = "W-L" shirts[6] = "B-S" shirts[7] = "B-M" shirts[8] = "B-L" doneThis = 0 shirtImg = new Array() // Preload shirt images for(idx=0.shirt.gif"></TD> <TD> <FORM> <B>Color</B> <SELECT SIZE=3 NAME="color" onChange="changeShirt(this.src doneThis++ if(doneThis != 9)setTimeout("allShirts()".shirt.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. idx++) { shirtImg[idx] = new Image() shirtImg[idx].src = shirtImg[doneThis].size.options[form.selectedIndex].form)"> <OPTION> Small <OPTION> Medium <OPTION SELECTED> Large file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.form)"> <OPTION> Red <OPTION SELECTED> White <OPTION> Blue </SELECT> <P> <B>Size</B> <SELECT SIZE=3 NAME="size" onChange="changeShirt(this.src = newSrc } function allShirts() { document. 500) else doneThis = 0 return } </SCRIPT> <FONT SIZE=+2><B>Netscape Polo Shirts!</FONT></B> <TABLE CELLSPACING=20 BORDER=0> <TR> <TD><IMG name="shirt" SRC="shirt-W-L.gif" document.size.text newSrc = "shirt-" + shirtColor.color.color. idx < 9.options[form.charAt(0) + ".selectedIndex].gif" } function changeShirt(form) { shirtColor = form.htm (19 of 49) [30/08/2003 9:34:21 PM] .text shirtSize = form.src = "shirt-" + shirts[idx] + ".

Notice that the animate function does not call itself after changing the src property of the Image object.animation. image3.gif.htm (20 of 49) [30/08/2003 9:34:21 PM] .src imageNum++ if(imageNum > 10) { imageNum = 1 } } function slower() { delay+=10 if(delay > 4000) delay = 4000 } function faster() { delay-=10 if(delay < 0) delay = 0 } </SCRIPT> <BODY BGCOLOR="white"> <IMG NAME="animation" SRC="image1. This is because when the src property changes. i < 11. When the Image object is placed on the document with the <IMG> tag.gif. and so on).src = theImages[imageNum]. The following example uses JavaScript to create an animation with an Image object by repeatedly changing the value the src property.gif.htm </SELECT> <P><INPUT type="button" name="buy" value="Buy This Shirt!" onClick="allShirts()"> </FORM> </TD> </TR> </TABLE> Example 4: JavaScript animation. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.gif" } function animate() { document. image2. image1.src = "image" + i + ". <SCRIPT> delay = 100 imageNum = 1 // Preload animation images theImages = new Array() for(i = 1. delay)"> <FORM> <INPUT TYPE="button" Value="Slower" onClick="slower()"> <INPUT TYPE="button" Value="Faster" onClick="faster()"> </FORM> </BODY> See also the examples for the onAbort. i++) { theImages[i] = new Image() theImages[i]. and onLoad event handlers.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.gif" ALT="[Animation]" onLoad="setTimeout('animate()'. The script begins by preloading the 10 images that make up the animation (image1.gif is displayed and the onLoad event handler starts the animation by calling the animate function. onError. the image's onLoad event handler is triggered and the animate function is called.

options array (see the Select object) Implemented in q q Navigator 2. onMouseOut. onClick. index Property. An array reflecting all the images in a document in source order. indexValue is an integer representing an option in a Select object.index 2. starting from zero. onMouseOver event handlers images Property. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. See the Image object for information.options[indexValue].index Parameters selectName is either the value of the NAME attribute of a Select object or an element in the elements array.0: property of Option Tainted? No Description The number identifying the position of the option in the selection. optionName is the name of a Select object option created using the Option() constructor. optionName.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. Property of Option object (see the Select object).0 Navigator 3. Syntax 1. selectName.htm (21 of 49) [30/08/2003 9:34:21 PM] .htm See also Link object. An integer representing the index of an option in a Select object.

and the index of the last character is stringName. searchValue is a string or a property of an existing object. If you do not specify a value for fromIndex.indexOf(searchValue. The index of the first character is zero. It can be any integer from zero to stringName. Syntax stringName.indexOf("blue") file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. selected. For example.length . [fromIndex]) Parameters stringName is any string or a property of an existing object. Returns the index within the calling String object of the first occurrence of the specified value. fromIndex is the location within the calling string to start the search from. JavaScript returns -1.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. If stringName contains an empty string (""). the following expression returns -1: "Blue Whale". The indexOf method is case sensitive.length 1 or a property of an existing object. selectedIndex properties indexOf Method.htm See also defaultSelected. If searchValue is not found.htm (22 of 49) [30/08/2003 9:34:22 PM] . starting the search at fromIndex.0 Description Characters in a string are indexed from left to right. indexOf returns an empty string.1. JavaScript assumes zero by default. Method of String Implemented in Navigator 2. representing the value to search for.

so the second writeln method displays -1.writeln('<P>myCapString. The first writeln method displays 19.write("<P>The index of 'new' from the end is " + anyString. But because the indexOf method is case sensitive. myString="brie. The following example uses indexOf and lastIndexOf to locate values in the string "Brave new world.indexOf("cheddar")) See also charAt. Syntax isNaN(testValue) Parameters testValue is the value you want to evaluate.htm Examples Example 1.indexOf("new")) //Displays 6 document.indexOf("cheddar") is ' + myString.writeln('myString.lastIndexOf("new")) Example 2. cheddar" myCapString="Brie.indexOf("cheddar") is ' + myCapString. split methods isNaN Function. Evaluates an argument to determine if it is "NaN" (not a number). lastIndexOf.write("<P>The index of 'new' from the beginning is " + anyString. The variables contain the same string except that the second string contains uppercase letters. Pepper Jack.indexOf("w")) //Displays 10 document.write("<P>The index of the first w from the beginning is " + anyString. The following example defines two string variables.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. the string "cheddar" is not found in myCapString.write("<P>The index of the first w from the end is " + anyString." var anyString="Brave new world" //Displays 8 document. pepper jack. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. Cheddar" document.indexOf("cheddar")) document.lastIndexOf("w")) //Displays 6 document.htm (23 of 49) [30/08/2003 9:34:22 PM] .

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

Implemented in
q q

Navigator 2.0 Navigator 3.0: works on all platforms (in previous releases, worked only on Unix platforms)

Description
isNaN is a built-in JavaScript function. It is not a method associated with any object, but is part of the language itself. On platforms that support NaN, the parseFloat and parseInt functions return "NaN" when they evaluate a value that is not a number. isNaN returns true if passed "NaN," and false otherwise.

Examples
The following example evaluates floatValue to determine if it is a number and then calls a procedure accordingly: floatValue=parseFloat(toFloat) if (isNaN(floatValue)) { notFloat() } else { isFloat() }

See also
NaN property; parseFloat, parseInt functions

italics
Method. Causes a string to be italic, as if it were in an <I> tag.

Syntax
stringName.italics()

Parameters
stringName is any string or a property of an existing object.

Method of
String

Implemented in
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (24 of 49) [30/08/2003 9:34:22 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

Navigator 2.0

Description
Use the italics method with the write or writeln methods to format and display a string in a document.

Examples
The following example uses string methods to change the formatting of a string: var worldString="Hello, world" document.write(worldString.blink()) document.write("<P>" + worldString.bold()) document.write("<P>" + worldString.italics()) document.write("<P>" + worldString.strike()) The previous example produces the same output as the following HTML: <BLINK>Hello, world</BLINK> <P><B>Hello, world</B> <P><I>Hello, world</I> <P><STRIKE>Hello, world</STRIKE>

See also
blink, bold, strike methods

javaEnabled
Method. Specifies whether Java is enabled.

Syntax
navigator.javaEnabled()

Method of
navigator

Implemented in
Navigator 3.0

Description
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (25 of 49) [30/08/2003 9:34:22 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

javaEnabled returns true if Java is enabled, false otherwise. The user can enable or disable Java by choosing Network Preferences from the Navigator's Options menu.

Examples
The following code executes function1 if Java is enabled; otherwise it executes function2. if (navigator.javaEnabled()) { function1() } else function2()

See also
appCodeName, appName, userAgent properties

join
Method. Joins all elements of an array into a string.

Syntax
arrayName.join(separator)

Parameters
arrayName is the name of an Array object or a property of an existing object. separator specifies a string to separate each element of the array. The separator is converted to a string if necessary. If omitted, the array elements are separated with a comma (,).

Method of
Array

Implemented in
Navigator 3.0

Description
The string conversion of all array elements are joined into one string.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (26 of 49) [30/08/2003 9:34:22 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

Examples
The following example creates an array, a with three elements, then joins the array three times: using the default separator, then a comma and a space, and then a plus. a = new Array("Wind","Rain","Fire") document.write(a.join() +"<BR>") document.write(a.join(", ") +"<BR>") document.write(a.join(" + ") +"<BR>") This code produces the following output: Wind,Rain,Fire Wind, Rain, Fire Wind + Rain + Fire

See also
reverse, sort methods

lastIndexOf
Method. Returns the index within the calling String object of the last occurrence of the specified value. The calling string is searched backward, starting at fromIndex.

Syntax
stringName.lastIndexOf(searchValue, [fromIndex])

Parameters
stringName is any string or a property of an existing object. searchValue is a string or a property of an existing object, representing the value to search for. fromIndex is the location within the calling string to start the search from. It can be any integer from zero to stringName.length 1 or a property of an existing object.

Method of
String

Implemented in
Navigator 2.0
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (27 of 49) [30/08/2003 9:34:22 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

Description
Characters in a string are indexed from left to right. The index of the first character is zero, and the index of the last character is stringName.length - 1. If you do not specify a value for fromIndex, JavaScript assumes stringName.length - 1 (the end of the string) by default. If searchValue is not found, JavaScript returns -1. The lastIndexOf method is case sensitive. For example, the following expression returns -1: "Blue Whale, Killer Whale".lastIndexOf("blue")

Examples
The following example uses indexOf and lastIndexOf to locate values in the string "Brave new world." var anyString="Brave new world" //Displays 8 document.write("<P>The index of the first w from the beginning is " + anyString.indexOf("w")) //Displays 10 document.write("<P>The index of the first w from the end is " + anyString.lastIndexOf("w")) //Displays 6 document.write("<P>The index of 'new' from the beginning is " + anyString.indexOf("new")) //Displays 6 document.write("<P>The index of 'new' from the end is " + anyString.lastIndexOf("new"))

See also
charAt, indexOf, split methods

lastModified
Property. A string representing the date that a document was last modified.

Syntax
document.lastModified

Property of

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (28 of 49) [30/08/2003 9:34:22 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

document

Implemented in
Navigator 2.0

Tainted?
Yes

Description
The lastModified property is derived from the HTTP header data sent by the web server. Servers generally obtain this date by examining the file's modification date. The last modified date is not a required portion of the header, and some servers do not supply it. If the server does not return the last modified information, JavaScript receives a zero, which it displays as January 1, 1970 GMT. The following code checks the date returned by lastModified and prints out a value that corresponds to unknown. lastmod = document.lastModified lastmoddate = Date.parse(lastmod) if(lastmoddate == 0){ // get string of last modified date // convert modified string to date // unknown date (or January 1, // 1970 GMT) document.writeln("Lastmodified: Unknown") } else { document.writeln("LastModified: " + lastmod)

} lastModified is a read-only property.

Examples
In the following example, the lastModified property is used in a <SCRIPT> tag at the end of an HTML file to display the modification date of the page: document.write("This page updated on " + document.lastModified)

length
Property. An integer that specifies a length-related feature of the calling object or array.

Syntax
When used with objects:

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (29 of 49) [30/08/2003 9:34:22 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

1. 2. 3. 4. 5. 6. 7. 8.

formName.length frameReference.length history.length radioName.length selectName.length stringName.length windowReference.length arrayName.length

When used with array properties: 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. anchors.length applets.length arguments.length elements.length embeds.length forms.length frames.length history.length images.length links.length mimeTypes.length plugins.length plugins[mimeTypeIndex].length selectName.options.length

Parameters
formName is either the name of a form or an element in the forms array. frameReference is either the value of the NAME attribute of a frame or an element in the frames array. radioName is either the value of the NAME attribute of a Radio object or an element in the elements array. selectName is either the value of the NAME attribute of a Select object or an element in the elements array. stringName is any string or a property of an existing object. windowReference is a valid way of referring to a window, as described in the window object. arrayName is the name of an Array object. mimeTypeIndex is either an integer representing a MIME type supported by the plug-in or a string containing the type of a MimeType object (from the type property).

Property of
q q

Array object, Frame object, history object, Radio object, Select object, String object, window object anchors array, arguments array, elements array, forms array, frames array, images array, links array, mimeTypes array,

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (30 of 49) [30/08/2003 9:34:22 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

options array (see Select object), plugins array

Implemented in
q q

Navigator 2.0 Navigator 3.0: property of applets array, Array object, embeds array, history array, images array, mimeTypes array, plugins array

Tainted?
No

Description
The length property is an integer that specifies one of the following:
q q

q q q q q q q q q q

The number of elements on a form (form 1 of the syntax). The number of frames within a frame (form 2 of the syntax). A frame that does not load a document containing a <FRAMESET> tag always has a length of zero. The number of entries in a history object (form 3 of the syntax). The number of radio buttons in a Radio object (form 4 of the syntax). The number of options in a Select object (form 5 of the syntax). The length of a String object (form 6 of the syntax). The number of frames in a parent window (form 7 of the syntax). The number of elements in an array (form 8 of the syntax). The number of MIME types supported by the client (form 19 of the syntax). The number of plug-in modules installed on the client (form 20 of the syntax). The number of elements in a Plugin object's array of MimeType objects (form 21 of the syntax). The number of entries in one of the array properties (all other syntax forms).

For all objects except Array objects, length is always a read-only property. For a null string, length is zero. For a Select object, the values returned by form 5 and form 22 of the syntax are the same. For a window containing frames, the values returned by form 7 and form 15 of the syntax are the same. For a Form object, the values returned by form 1 and form 12 of the syntax are the same. For a frame containing frames, the values returned by form 2 and form 15 of the syntax are the same. For arrays, you can set the length property to truncate an array at any time. You cannot extend an array; for example, if you set length to 3 when it is currently 2, the array will still contain only 2 elements. For information on other ways to change the length of an array, see the Array object.

Examples
In the following example, the getChoice function uses the length property to iterate over every element in the musicType array. musicType is a select element on the musicForm form. function getChoice() { for (var i = 0; i < document.musicForm.musicType.length; i++) { if (document.musicForm.musicType.options[i].selected == true) {
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (31 of 49) [30/08/2003 9:34:22 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

return document.musicForm.musicType.options[i].text } } } The following example displays 8 in an Alert dialog box: var x="Netscape" alert("The string length is " + x.length) The following example shortens the array statesUS to a length of 50 if the current length is greater than 50. if (statesUS.length > 50) { statesUS.length=50 alert("The U.S. has only 50 states. New length is " + statesUS.length) }

link method
Method. Creates an HTML hypertext link that requests another URL.

Syntax
linkText.link(hrefAttribute)

Parameters
linkText is any string or a property of an existing object. This represents the text that will be displayed in the link. hrefAttribute is any string that specifies the HREF attribute of the <A> tag; it should be a valid URL (relative or absolute).

Method of
String

Implemented in
Navigator 2.0

Description
Use the link method to programmatically create a hypertext link, and then call write or writeln to display the link in a document. Links created with the link method become elements in the links array. See the Link object for information about the links
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (32 of 49) [30/08/2003 9:34:22 PM]

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm

array.

Examples
The following example displays the word "Netscape" as a hypertext link that returns the user to the Netscape home page: var hotText="Netscape" var URL="http://home.netscape.com" document.write("Click to return to " + hotText.link(URL)) The previous example produces the same output as the following HTML: Click to return to <A HREF="http://home.netscape.com">Netscape</A>

See also
Anchor object

Link object
Object. A piece of text, an image, or an area of an image identified as a hypertext link. When the user clicks the link text, image, or area, the link hypertext reference is loaded into its target window. Area objects are a type of Link object.

HTML syntax
To define a link, use standard HTML syntax with the addition of JavaScript event handlers: <A HREF=locationOrURL [NAME="anchorName"] [TARGET="windowName"] [onClick="handlerText"] [onMouseOut="handlerText"]> [onMouseOver="handlerText"]> linkText </A> You can also define a link using the link method. To define an area, use standard HTML syntax with the addition of JavaScript event handlers: <MAP NAME="mapName"> <AREA [NAME="areaName"] COORDS="x1,y1,x2,y2,..."|"x-center,y-center,radius" HREF="locationOrURL" [SHAPE="rect"|"poly"|"circle"|"default"]
file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (33 of 49) [30/08/2003 9:34:22 PM]

frameName or windowName. it cannot be parent. You can specify this map name in the USEMAP attribute of the <IMG> tag.propertyName Parameters index is an integer representing a Link or Area object or the name of a Link or Area object as specified by the NAME attribute. NAME="mapName" specifies the name of the map.links[index]. If omitted. this attribute is required if you include the onMouseOut and onMouseOver event handlers. Property of document file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. linkText is the text or HTML source that the user sees as a hypertext link to the URL. This attribute is not reflected in JavaScript (you cannot refer to an Area object by name). For areas.frameName). See the location object for a description of the URL components.htm [TARGET="windowName"] [onMouseOut="handlerText"] [onMouseOver="handlerText"]> </MAP> HTML attributes HREF=locationOrURL identifies a destination anchor or URL. or _blank. NAME="anchorName" is used only if the link is also an anchor. AREA defines an area of an image as an image map. It cannot be a JavaScript expression (for example. NAME="areaName" specifies the name of the Area object. _parent. _self. or it can be one of the literal frame names _top. COORDS specifies the coordinates of the image map. TARGET="windowName" specifies the frame or window that the link is loaded into. any region of an image that does not have an HREF attribute does not function as a hyperlink. "rect" is used.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. windowName can be an existing window. propertyName is one of the properties listed below.htm (34 of 49) [30/08/2003 9:34:22 PM] . It specifies a name for the anchor that then becomes an available hypertext target within the current document. See the Anchor object for details. SHAPE specifies the shape of the map. it can be a frame name specified in a <FRAMESET> tag. For areas. "default" specifies a region as the default. Syntax To use a Link or Area object's properties: document.

If a Link object is also an Anchor object. links array contains areas created with <AREA HREF=". The HREF attribute is required for Area objects that use the onMouseOut or onMouseOver event handlers.return true"> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. and document. the slower and faster functions execute: <A HREF="javascript:slower()">Slower</A> <A HREF="javascript:faster()">Faster</A> You can use a Link object to do nothing rather than link to a hypertext reference by specifying the javascript:void(0) URL protocol for the link's HREF attribute. the function onTop executes. You might want to do this if the link surrounds an Image object and you want to execute JavaScript code when the image is clicked. When a user clicks the following link or image. if a user clicks the following Area object. you must use the links array. For example.0: added onMouseOut event handler. For example.status='You are on top of the world'.0.links[1].gif" ALIGN="top" HEIGHT="50" WIDTH="50"> </A> Area objects Area objects are in the links array."> Description Each Link object is a location object and has the same properties as a location object. when a user clicks the following links. added Area objects. if a document contains three Area objects. see "The links array". nothing happens: <A HREF="javascript:void(0)">Click here to do nothing</A> <A HREF="javascript:void(0)"> <IMG SRC="images\globe. Or you might want to use a link instead of a button to execute JavaScript code.status='You have left the top of the world'. You might want to do this if the link surrounds an Image object and you want to use the link's event handlers with the image.0 Navigator 3.links[0]. document..file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (35 of 49) [30/08/2003 9:34:22 PM] . these objects are reflected as document. the object has entries in both the anchors and links arrays..htm Implemented in q q Navigator 2. For information on the links array. Evaluate the referrer property from the destination document. When a user clicks a Link object and navigates to the destination document (specified by HREF=locationOrURL). the destination document's referrer property contains the URL of the source document. You can use a Link object to execute a JavaScript function rather than link to a hypertext reference by specifying the javascript: URL protocol for the link's HREF attribute. specify a JavaScript function in the area's HREF attribute by using the javascript: URL protocol.links[2]. You cannot refer to an Area object by name.50.return true" onMouseOut="self.25" HREF="javascript:onTop()" onMouseOver="self. <MAP NAME="worldMap"> <AREA NAME="topWorld" COORDS="0. For example. However. if you create an Area for an image and do not want the image to link to a hypertext reference when clicked.

To obtain the number of links in a document.links[1].links[0].return true"> </MAP> The links array You can reference the Area and Link objects in your code by using the links array..links[index] 2.status='You have left the top of the world'.0. For example. nothing happens: <MAP NAME="worldMap"> <AREA NAME="topWorld" COORDS="0.length.For example. and document.return true" onMouseOut="self. This array contains an entry for each Area (<AREA HREF=". document. When the user clicks the following Area object. use the length property: document.25" HREF="javascript:void(0)" onMouseOver="self. use javascript:void(0) in the HREF attribute.status='You are on top of the world'.links[0]="link1" has no effect. the statement document..length index is an integer representing a link in a document or the name of a Link object as specified by the NAME attribute. including the colon search target Specifies a query Reflects the TARGET attribute The links array has the following property: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (36 of 49) [30/08/2003 9:34:22 PM] . of a network host hostname Specifies the host:port portion of the URL href Specifies the entire URL pathname Specifies the url-path portion of the URL port Specifies the communications port that the server uses for communications protocol Specifies the beginning of the URL.50. document.htm </MAP> If you want an area's link to do nothing. Properties The Area and Link objects have the following properties: Property Description hash host Specifies an anchor name in the URL Specifies the host and domain name. It also contains links created with the link method. document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.links. if a document contains three Link objects."> tag) and Link (<A HREF=""> tag) object in a document in source order.links[2]. To use the links array: 1. or IP address.links. Elements in the links array are read-only. these links are reflected as document.

The user can use the set of radio buttons to choose between three URLs. <SCRIPT> var destHREF="http://home. The link also has an onMouseOver event handler that changes the window's status property.netscape.htm Property Description length Reflects the number of links in a document Methods q q q eval toString valueOf Event handlers Area objects have the following event handlers: q q onMouseOut onMouseOver Link objects have the following event handlers: q q q onClick onMouseOut onMouseOver Examples Example 1. The following example creates a hypertext link to a URL.status property in the onMouseOver event handler. it is created. The following example takes the user back x entries in the history list: <A HREF="javascript:history. The following example creates a hypertext link to an anchor named numbers in the file doc3. As the example shows.</B> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (37 of 49) [30/08/2003 9:34:22 PM] . then click "Click me" below.html#numbers TARGET="window2">Numbers</A> Example 3. <LI><A HREF=doc3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. The following example creates a hypertext link to an anchor named javascript_intro: <A HREF="#javascript_intro">Introduction to JavaScript</A> Example 2. you must return true to set the window. The link's onClick event handler sets the URL (the link's href property) based on the selected radio button. If window2 does not exist.html in the window window2.com/" </SCRIPT> <FORM NAME="form1"> <B>Choose a destination from the following list.go(-1 * x)">Click here</A> Example 4.

In the following example.com/'"> Netscape home page <BR><INPUT TYPE="radio" NAME="destination" VALUE="sun" onClick="destHREF='http://www.links.supernet.status='Click this if you dare!'. return true" onClick="this.0.return true"> <AREA NAME="bottomWorld" COORDS="0.length.50.return true"> </MAP> <IMG SRC="images\globe.gif" ALIGN="top" HEIGHT="50" WIDTH="50" USEMAP="#worldMap"> Example 7: Refer to Area object with links array. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.href=destHREF"> <B>Click me</B></A> </FORM> Example 5: links array. <MAP NAME="worldMap"> <AREA NAME="topWorld" COORDS="0.write("links."msg". The following example displays an image. the linkGetter function uses the links array to display the value of each link in the current document.open("".edu/pub/ietf/html/rfc1867. function linkGetter() { msgWindow=window.netscape. The onMouseOver and onMouseOut event handlers display different status bar messages depending on whether the mouse passes over or leaves the top half or bottom half of the image.netscape.catalog.status='You are on the bottom of the world'.return true" onMouseOut="self.25. so the HREF attribute executes javascript:void(0). globe.uci.status='You have left the top of the world'. The following code refers to the href property of the first Area object shown in Example 1. i++) { msgWindow.links[i] + "<BR>") } } <A HREF="http://home.document.50" HREF="javascript:void(0)" onMouseOver="self.shtml">Lab Rescue</A> <P> <INPUT TYPE="button" VALUE="Display links" onClick="linkGetter()"> Example 6: Area object with onMouseOver and onMouseOut event handlers.net/~dugbrown/">Bad Dog Chronicles</A> <A HREF="http://www.status='You are on top of the world'.document.links.txt'"> RFC 1867 <P><A HREF="" onMouseOver="window. which does nothing (see "void" for more information).50.write(document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.ics.25" HREF="javascript:void(0)" onMouseOver="self.com/~doghouse/homecnt.length + "<BR>") for (var i = 0.length is " + document. The example also defines several links and a button for running linkGetter. The HREF attribute is required when using the onMouseOver and onMouseOut event handlers.htm (38 of 49) [30/08/2003 9:34:22 PM] .htm <BR><INPUT TYPE="radio" NAME="destination" VALUE="netscape" onClick="destHREF='http://home.com/fwcfc/">China Adoptions</A> <A HREF="http://www. but in this example the image does not need a hypertext link.sun.com/'"> Sun home page <BR><INPUT TYPE="radio" NAME="destination" VALUE="rfc1867" onClick="destHREF='http://www.return true" onMouseOut="self.status='You have left the bottom of the world'. The image uses an image map that defines areas for the top half and the bottom half of the image.best.com">Netscape Home Page</A> <A HREF="http://www.height=400") msgWindow. i < document.gif."width=400.

The following example uses an Area object's HREF attribute to execute a JavaScript function. colors. shows two sample colors.gif" ALIGN="top" HEIGHT="50" WIDTH="50" USEMAP="#colorMap"> See also Anchor object.htm (39 of 49) [30/08/2003 9:34:22 PM] .href Example 8: Simulate an Area object's onClick using the HREF attribute.linkColor Property of document Implemented in Navigator 2. The image displayed.25. link method linkColor Property. The top half of the image is the color "antiquewhite".25" HREF="javascript:setBGColor('antiquewhite')"> <AREA NAME="bottomColor" COORDS="0. When the user clicks the top or bottom half of the image.0.50" HREF="javascript:setBGColor('white')"> </MAP> <IMG SRC="images\colors.links[0]. Syntax document.50. Image object. A string specifying the color of the document hyperlinks. <SCRIPT> function setBGColor(theColor) { document. the function setBGColor changes the document's background color to the color shown in the image.bgColor=theColor } </SCRIPT> Click the color you want for this document's background color <MAP NAME="colorMap"> <AREA NAME="topColor" COORDS="0. and the bottom half is "white".file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.50.gif.htm document.0 Tainted? No file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.

If you express the color as a hexadecimal RGB triplet. green=80. approximately 0.LN2 Property of file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (40 of 49) [30/08/2003 9:34:22 PM] . fgColor.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.linkColor="00FFFF" See also alinkColor. For example. See the Link object for information.htm Description The linkColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in "Color values". bgColor. This property is the JavaScript reflection of the LINK attribute of the <BODY> tag. An array of objects corresponding to Area and Link objects in source order. The default value of this property is set by the user on the Colors tab of the Preferences dialog box.693.linkColor="aqua" The following example sets the color of document links to aqua using a hexadecimal triplet: document. and blue=72. The natural logarithm of two." Examples The following example sets the color of document links to aqua using a string literal: document. the hexadecimal RGB values for salmon are red=FA. which is displayed by choosing General Preferences from the Options menu. Tainted? Yes LN2 Property. Syntax Math. so the RGB triplet for salmon is "FA8072. vlinkColor properties links Property. You cannot set this property after the HTML source has been through layout. you must use the format rrggbb.

Syntax Math. SQRT2 properties LN10 Property.302. Examples The following function returns the natural log of two: function getNatLog2() { return Math. PI.LN2 } See also E. LOG10E.htm Math Implemented in Navigator 2. it is a read-only property of Math. approximately 2.htm (41 of 49) [30/08/2003 9:34:22 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. LOG2E. SQRT1_2. The natural logarithm of 10.0 Tainted? file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.0 Tainted? No Description Because LN2 is a constant.LN10 Property of Math Implemented in Navigator 2. LN10.

propertyName is one of the properties listed below.]location. methodName is one of the methods listed below.propertyName] [windowReference. Examples The following function returns the natural log of 10: function getNatLog10() { return Math. PI. SQRT2 properties location Object. or one of the synonyms top or parent. Omitting the property name is equivalent to specifying the href property (the complete URL). LOG2E. Property of window object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.LN10 } See also E. LN2. LOG10E.htm (42 of 49) [30/08/2003 9:34:22 PM] . it is a read-only property of Math.htm No Description Because LN10 is a constant. Syntax To use a location object: [windowReference. SQRT1_2.]location[.methodName(parameters) Parameters windowReference is a variable windowVar from a window definition (see the window object). Contains information on the current URL.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.

windowReference. The following diagram of a URL shows the relationships between the location properties: protocol//host:port/pathname#hash?search For example: http://home.0 Navigator 3. pathname represents the url-path portion of the URL.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. If you reference a location object and specify a window name.html#topic1?x=7&y=2 Following is a description of each part of the URL diagram: q q q q q q protocol represents the beginning of the URL.propertyName. up to and including the first colon.com/" window.com/" The location object is contained by the window object and is within its scope. you must specify window.location. hash represents an anchor name fragment in the URL. search represents any query information in the URL.htm Implemented in q q Navigator 2.netscape.location .netscape. or the href property for examples. This property applies to http URLs only. In event handlers. including the question mark (?). of a network host. replace methods.URL. hostname represents the concatenation host:port.href. host represents the host and domain name. This property applies to http URLs only. port represents the communications port that the server uses for communications.netscape. for example. See the properties (listed below) for details about the different parts of the URL.com/assist/extensions. changed the way documents are loaded when location is set Description The location object represents a complete URL.href="http://home. each pair is separated by an ampersand (&).location instead of simply using location. or IP address. Due to the scoping of static objects in JavaScript. If you reference a location object without specifying a window. Each property of the location object represents a different portion of the URL.location="http://home. which is a synonym for document.0: added reload. the location object represents the location of the specified window. The search string contains variable and value pairs. including the hash mark (#). For example. the following two statements are equivalent and set the URL of the current window to the Netscape home page: window.htm (43 of 49) [30/08/2003 9:34:22 PM] . the location object represents the current location. Omitting a property name from the location object is equivalent to specifying location.location. a call to location without specifying an object name is equivalent to document. The location object has two other properties not shown in the diagram above: q q href represents a complete URL. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.

netscape. functions. the effect of setting location depends on the user's setting for verifying documents.0. This is the same as choosing About Plug-ins file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. or Never.location property. and so on. Note that loading a new page over your script's page clears the page's variables.) The document is reloaded from cache if the user sets Never or Once Per Session. use the document. (The user chooses Network Preferences from the Options menu and on the Cache tab. How documents are loaded when location is set When you set the location object or any of its properties except hash. you can use standard URL formats and JavaScript statements.lang. The about: protocol provides information on Navigator and has the following syntax: about:[cache|plugins] q q q about: by itself is the same as choosing About Netscape from the Navigator Help menu. will be removed in a future release. which returns no data from the server unless the document has been modified since the last version downloaded. if there is one.html The javascript: protocol evaluates the expression after the colon (:). setting location does a conditional ("If-modified-since") HTTP GET operation.javascript gopher. which is a synonym for document.com/home/mine mailto:info@netscape. for example javascript:void(0)). In Navigator 3.html ftp://ftp. whether a new document is loaded depends on which version of Navigator you are running: q q In Navigator 2. about:plugins displays information about plug-ins you have configured. see the write method.htm (44 of 49) [30/08/2003 9:34:22 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. The view-source: protocol displays HTML code that was generated with JavaScript write and writeln methods. the document is reloaded from the server only if the user chooses Every Time.scruznet. URL type JavaScript code Navigator info World Wide Web File FTP MailTo Usenet Gopher Protocol javascript: about: http: file:/ ftp: mailto: news: gopher: Example javascript:history.com Navigator source viewer view-source: view-source:wysiwyg://0/file:/c|/temp/genhtml. no new page loads. For information on printing and saving generated HTML. The document. unless it is undefined.com news://news.htm Do not use location as a property of the document object. The following list shows the syntax for specifying some of the most common types of URLs.URL property instead. specifies one of the following for Verify Documents: Once Per Session.go(-1) about:cache http://home.URL. Every Time.mine.0. If the expression evaluates to undefined (by calling a void function.com/ file:///javascript/methods.myhost. and loads a page containing the string value of the expression.com/comp. about:cache displays disk-cache statistics. Syntax for common URL types When you specify a URL.

location.location="http://home.href="http://www.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. URL property file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. including the colon search Specifies a query Methods The location object has the following methods: q q q eval reload replace q q toString valueOf Event handlers None.href="http://home.htm (45 of 49) [30/08/2003 9:34:22 PM] .com/" See also the examples for the Anchor object.frame2. See also history object. The following two statements are equivalent and set the URL of the current window to the Netscape home page: window.netscape. or IP address.sun.com/" window.htm from the Navigator Help menu.com/" Example 2. Examples Example 1.netscape.location. Properties The location object has the following properties: Property Description hash host Specifies an anchor name in the URL Specifies the host and domain name. of a network host hostname specifies the host:port portion of the URL href Specifies the entire URL pathname Specifies the url-path portion of the URL port Specifies the communications port that the server uses for communications protocol Specifies the beginning of the URL. The following statement sets the URL of a frame named frame2 to the Sun home page: parent.

htm log Method. Examples The following function returns the natural log of the variable x: function getLog(x) { return Math. Syntax Math. Method of Math Implemented in Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. it returns 2. it returns 1. Returns the natural logarithm (base e) of a number. pow methods LOG2E file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. the return value is always -1.797693134862316e+308 because zero is out of range.0 Description If the value of number is outside the suggested range. See also exp.log(x) } If you pass getLog the value 10.log(number) Parameters number is any positive numeric expression or a property of an existing object. if you pass it the value zero.302585092994046.htm (46 of 49) [30/08/2003 9:34:22 PM] .797693134862316e+308.

SQRT1_2. it is a read-only property of Math. LN2. LOG10E. LN10. Syntax Math.434).htm Property.LOG10E Property of file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.htm (47 of 49) [30/08/2003 9:34:22 PM] .442).0 Tainted? No Description Because LOG2E is a constant. Syntax Math.LOG2E } See also E. PI. The base 2 logarithm of e (approximately 1.LOG2E Property of Math Implemented in Navigator 2. The base 10 logarithm of e (approximately 0. Examples The following function returns the base 2 logarithm of E: function getLog2e() { return Math. SQRT2 properties LOG10E Property.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.

LN2. Property of Image file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l.0 Tainted? No Description Because LOG10E is a constant. Examples The following function returns the base 10 logarithm of E: function getLog10e() { return Math. Syntax imageName. LOG2E. LN10.htm (48 of 49) [30/08/2003 9:34:22 PM] .LOG10E } See also E. A string specifying the URL of a low-resolution version of an image to be displayed in a document. PI.htm Math Implemented in Navigator 2.lowsrc Parameters imageName is either the name of an Image object or an element in the images array. SQRT1_2. SQRT2 properties lowsrc Property. it is a read-only property of Math.

htm Implemented in Navigator 3. src properties [Next reference file] file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. See also complete.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_h-l. You can change the lowsrc property at any time.htm (49 of 49) [30/08/2003 9:34:22 PM] . Examples See the examples for the src property.0 Tainted? No Description The lowsrc property initially reflects the LOWSRC attribute of the <IMG> tag. Navigator loads the smaller image specified by lowsrc and then replaces it with the larger image specified by the src property.

propertyName 2. A built-in object that has properties and methods for mathematical constants and functions.0 Description You reference the constant PI as Math. For example. the Math object's PI property has the value of pi.methodName(parameters) Parameters propertyName is one of the properties listed below. where argument is the argument. The Math object is a top-level. the sine function is Math. Math. methodName is one of the methods listed below. For example.htm [Previous reference file] Math Object. built-in JavaScript object. Syntax To use a Math object: 1.PI.sin(argument). Implemented in Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. so you don't have to type "Math" repeatedly. It is often convenient to use the with statement when a section of code uses several Math constants and methods. Math. Similarly. For example. with a y x } (Math) { = PI * r*r = r*sin(theta) = r*cos(theta) Properties file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. you reference Math functions as methods.htm (1 of 64) [30/08/2003 9:34:26 PM] . Constants are defined with the full precision of real numbers in JavaScript. Property of None.

max Method.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Syntax Math. Method of file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Returns the greater of two numbers.max(number1. number2) Parameters number1 and number2 are any numeric arguments or the properties of existing objects.htm (2 of 64) [30/08/2003 9:34:26 PM] .htm The Math object has the following properties: q q q q E LN2 LN10 LOG2E q q q q LOG10E PI SQRT1_2 SQRT2 Methods The Math object has the following methods: q q q q q q q abs acos asin atan atan2 ceil cos q q q q q q q eval exp floor log max min pow q q q q q q q random round sin sqrt tan toString valueOf Event handlers None. Examples See the examples for the individual properties and methods.

it returns -10.MAX_VALUE Property of Number Implemented in Navigator 3.y) { return Math. Syntax Number.0 Examples The following function evaluates the variables x and y: function getMax(x. if you pass it the values -10 and -20. The maximum numeric value representable in JavaScript.max(x. it returns 20.htm Math Implemented in Navigator 2.htm (3 of 64) [30/08/2003 9:34:26 PM] . See also min method MAX_VALUE Property.0 Tainted? No Description file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.y) } If you pass getMax the values 10 and 20.

Syntax formName. Examples The following code multiplies two numeric values. A string specifying how form field input information is sent to the server. it is a read-only property of Number. Values larger than MAX_VALUE are represented as "Infinity". NaN. Because MAX_VALUE is a constant.MAX_VALUE) func1() else func2() See also MIN_VALUE. the func2 function is called.0 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm (4 of 64) [30/08/2003 9:34:26 PM] .79E+308. POSITIVE_INFINITY properties method Property.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. NEGATIVE_INFINITY. If the result is less than or equal to MAX_VALUE.htm The maximum numeric value representable in JavaScript The MAX_VALUE property has a value of approximately 1. Property of Form object Implemented in Navigator 2.method Parameters formName is either the name of a form or an element in the forms array. the func1 function is called. otherwise. if (num1 * num2 <= Number.

mimeTypes[index]." You can set the method property at any time.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Examples The following function returns the value of the musicForm method property: function getMethod() { return document. Property of file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Form object MimeType Object. propertyName is one of the properties listed below.method } See also action. The method property should evaluate to either "get" or "post.musicForm. target properties. A MIME type (Multipart Internet Mail Extension) supported by the client.propertyName Parameters index is either an integer representing a MIME type supported by the client or a string containing the type of a MimeType object (from the type property). encoding. Syntax To use a MimeType object: navigator.htm Tainted? No Description The method property is a reflection of the METHOD attribute of the <FORM> tag.htm (5 of 64) [30/08/2003 9:34:26 PM] .

0 Description Each MimeType object is an element in the mimeTypes array. For example. jpg. navigator. via helper applications. each Plugin object also has an array of MimeType objects. Implemented in Navigator 3. For example. For example. Elements in the mimeTypes array are read-only.mimeTypes[index] 2.enabledPlugins null The mimeTypes array The mimeTypes array contains an entry for each MIME type supported by the client (either internally. and navigator. pjpeg.type navigator. jpe.mimeTypes. pjp navigator.mimeTypes[1].htm (6 of 64) [30/08/2003 9:34:26 PM] .htm The mimeTypes array is a property of navigator.mimeTypes[0]="video/quicktime" has no effect.mimeTypes["image/jpeg"].mimeTypes[2].length. The mimeTypes array used with the Plugin object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. To use the mimeTypes array: 1. the statement navigator. navigator.description navigator.mimeTypes["image/jpeg"].mimeTypes["image/jpeg"].length index is either an integer representing a MIME type supported by the client or a string containing the type of a MimeType object (from the type property). the following table summarizes the values for displaying JPEG images: Expression navigator.suffixes Value image/jpeg JPEG Image jpeg. use the length property: navigator.mimeTypes. these MIME types are reflected as navigator. To obtain the number of MIME types supported by the client. jfif. The MimeType object is a member of the mimeTypes array. or by plug-ins). navigator.mimeTypes["image/jpeg"]. if a client supports three MIME types.mimeTypes[0]. Each element of the mimeTypes array is a MimeType object.

vbs. see Plugin.navigator.writeln("<TR VALIGN=TOP><TD>". Examples The following code displays the type. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.name</TR>") for (i=0. which contains an entry for each MIME type handled by the plug-in. mpegv" The mimeTypes array has the following properties: Property Description length Reflects the number of MIME types supported by the client Methods q q q eval toString valueOf Event handlers None.mimeTypes[i]. for example "mpeg. "<TH ALIGN=left>i". "<TD>".mimeTypes[i]. For information.type. i < navigator. mpv. "<TH ALIGN=left>enabledPlugin.htm Each Plugin object has its own mimeTypes array. "<TH ALIGN=left>description".i.htm (7 of 64) [30/08/2003 9:34:26 PM] . and enabledPlugin properties for each MimeType object on a client: document. mpe.mimeTypes. "<TH ALIGN=left>type". suffixes. for example "video/mpeg or audio/x-wav" A string listing possible file name extensions for the MIME type. i++) { document.writeln("<TABLE BORDER=1><TR VALIGN=TOP>". "<TD>". Properties The MimeType object has the following properties: Property description Description A description of the type enabledPlugin A reference to the Plugin object configured for the MIME type type suffixes The name of the MIME type.description. description.length. mpg. "<TH ALIGN=left>suffixes".navigator.

mimeTypes[i].htm "<TD>". "</TR>") } else { document. An array of all MIME types supported by the client.writeln( "<TD>None".name LiveAudio LiveAudio mid.htm (8 of 64) [30/08/2003 9:34:26 PM] . "</TR>") } } document.navigator.writeln("</TABLE>") The preceding example displays output similar to the following: i type 0 audio/aiff 1 audio/wav 2 audio/x-midi 3 audio/midi 4 video/msvideo 5 * 6 zz-application/zz-winassoc-TGZ description AIFF WAV MIDI MIDI Video for Windows Netscape Default Plugin suffixes aif. midi LiveAudio mid.writeln( "<TD>".suffixes) if (navigator. See the MimeType object for information.enabledPlugin.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.mimeTypes[i]. aiff wav enabledPlugin.navigator. Tainted? No min file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.mimeTypes[i]. midi LiveAudio avi TGZ NPAVI32 Dynamic Link Library Netscape Default Plugin None See also Plugin object mimeTypes Property.enabledPlugin==null) { document.name.

min(number1.0 Examples The following function evaluates the variables x and y: function getMin(x.htm Method. if you pass it the values -10 and -20. The smallest positive numeric value representable in JavaScript. Syntax Number.MIN_VALUE Property of file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. See also max method MIN_VALUE Property.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Returns the lesser of two numbers.y) } If you pass getMin the values 10 and 20. number2) Parameters number1 and number2 are any numeric arguments or the properties of existing objects. it returns 10.htm (9 of 64) [30/08/2003 9:34:26 PM] . it returns -20.min(x. Method of Math Implemented in Navigator 2. Syntax Math.y) { return Math.

NaN. Examples The following code divides two numeric values. A string specifying the name of an object. POSITIVE_INFINITY properties Implemented in Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. it is a read-only property of Number. NEGATIVE_INFINITY.22E-308. If the result is greater than or equal to MIN_VALUE. Because MIN_VALUE is a constant. Values smaller than MIN_VALUE ("underflow values") are converted to zero. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.MIN_VALUE) func1() else func2() See also MAX_VALUE.0 Tainted? No Description The MIN_VALUE property is the number closest to zero. not the most negative number. the func2 function is called.htm Number Implemented in Navigator 3. that JavaScript can represent.0 name Property. MIN_VALUE has a value of approximately 2.htm (10 of 64) [30/08/2003 9:34:26 PM] . if (num1 / num2 >= Number. otherwise. the func1 function is called.

3. Textarea object. selectName is either the value of the NAME attribute of a Select object or an element in the elements array. Password object. frameReference is a valid way of referring to a frame.name frameReference. 8.name radioName[index].name navigator. Radio object. Property of Button object. 2. as described in the Frame object.frames. radioName is the value of the NAME attribute of a Radio object.frames. 6. Hidden object.name Parameters objectName is either the value of the NAME attribute of any of the objects listed below or an element in the elements array.0: property of FileUpload. Checkbox object. Submit object. and Plugin objects Tainted? Yes Description file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.0 Navigator 3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Image object. objectName. Text object. Form object.name imageName.htm (11 of 64) [30/08/2003 9:34:26 PM] . imageName is either the value of the NAME attribute of a Image object or an element in the images array. Form. Plugin object.plugins[index].name windowReference. 7. FileUpload object. 5. Select object. 4. Frame object. Reset object. index is either an integer representing a plug-in installed on the client or a string containing the name of a Plugin object (from the name property). windowReference is a valid way of referring to a window. Image. as described in the window object.name frameReference.name windowReference.htm Syntax 1. window object Implemented in q q Navigator 2.

the value of the name property is null. For Plugin objects. and window. it is used to reference the objects programmatically. The name property is the same for every radio button in a single Radio object. The value property specifies the label for these objects. Reset. Image object. Changing the name property overrides this setting. if two text elements and a textarea element on the same form have their NAME attribute set to "myField. For all objects except Image. and Plugin object. the valueGetter function uses a for loop to iterate over the array of elements on the valueTest file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. the values specified by forms 1. name is a read-only property. the name property represents the value of the NAME attribute. The name property is not displayed on-screen. All other objects The name property for all other objects is represented by forms 1 through 4 of the syntax. and 3 of the syntax are the same. Image and Plugin objects The name property for Image and Plugin objects is represented by forms 5-6 of the syntax. Examples In the following example. For example. the name property initially reflects the value of the NAME attribute. Individual radio buttons are referenced by their position in the Radio array. The name property represents the value of the windowName argument described in the window object syntax. q q For Image objects. window object The name property for the window object is represented by form 7 and form 8 of the syntax. Each element in the array represents an individual Form object. You can set the name property at any time. name is a read-only property.htm The value of the name property differs between the window object and other objects. Elements are indexed in source order starting at zero. and myField[2] is created. The name property is a read-only property for the FileUpload object. or Submit object. an array of the given name is created automatically. Plugin. For a Frame object. myField[1]. Do not confuse the name property with the label displayed on a Button. For images created with the Image() constructor. 2." an array with the elements myField[0]. the name property is the plug-in's name and is supplied by the plug-in itself.htm (12 of 64) [30/08/2003 9:34:26 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Both forms of the syntax represent the same value. If multiple objects on the same form have the same NAME attribute. Each plug-in should have a name that uniquely identifies it.

netscape. reset.htm form. A special value representing Not-A-Number. i++) { msgWindow.open("http://home.com".NaN Property of Number Implemented in Navigator 3.netscape.name + "<BR>") } } In the following example.htm (13 of 64) [30/08/2003 9:34:26 PM] . See also For button.elements[i].open("http://home.document."netscapeHomePage") alert(netscapeWin.0 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. the first statement creates a window called netscapeWin.valueTest. Syntax Number.write(newWindow. filename.valueTest. length properties NaN Property. This value is represented as the unquoted literal NaN.com") function valueGetter() { var msgWindow=window. i < newWindow. see the examples for the Plugin object.elements.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.name) For Plugin objects. The msgWindow window displays the names of all the elements on the form: newWindow=window. netscapeWin=window. The second statement displays the value "netscapeHomePage" in the Alert dialog box. and submit: value property For Plugin: description.document. because "netscapeHomePage" is the value of the windowName argument of netscapeWin.length.open("") for (var i = 0.document.

htm (14 of 64) [30/08/2003 9:34:26 PM] .htm Tainted? No Description JavaScript prints the value Number.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Use the isNaN function insead. including NaN itself. NEGATIVE_INFINITY. navigator. isNaN. Syntax To use a navigator object: 1. navigator. it is assigned NaN.NaN.NaN alert("Month must be between 1 and 12.propertyName 2. NaN always compares unequal to any other number. var month = 13 if (month < 1 || month > 12) { month = Number. parseInt functions navigator Object. POSITIVE_INFINITY properties. you cannot check for the not-a-number value by comparing to Number. Because NaN is a constant. MIN_VALUE.methodName file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Examples In the following example. You might use the NaN property to indicate an error condition for a function that should return a valid number.NaN as NaN. Contains information about the version of Navigator in use.") } See also MAX_VALUE. parseFloat. if month has a value greater than 12. and a message is displayed indicating valid values. it is a read-only property of Number.

Properties The navigator object has the following properties: Property appName appVersion mimeTypes plugins userAgent Description Specifies the name of the browser Specifies version information for the Navigator An array of all MIME types supported by the client An array of all plug-ins currently installed on the client Specifies the user-agent header appCodeName Specifies the code name of the browser Methods The navigator object has the following methods: q q q eval javaEnabled taintEnabled q q toString valueOf Event handlers file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.0: added mimeTypes.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.0 Navigator 3. and what plug-ins the user has installed. methodName is one of the methods listed below.htm Parameters propertyName is one of the properties listed below. what MIME types the user's Navigator can handle.htm (15 of 64) [30/08/2003 9:34:26 PM] . plugins properties. added javaEnabled method Description Use the navigator object to determine which version of the Navigator your users have. Property of None Implemented in q q Navigator 2.

htm (16 of 64) [30/08/2003 9:34:26 PM] . A special numeric value representing negative infinity. so the func1 function is called. Examples See the examples for the individual properties and methods.NEGATIVE_INFINITY Property of Number Implemented in Navigator 3. Examples In the following example. smallNumber has the value "-Infinity". for example.htm None. it is a read-only property of Number. This value is represented as "-Infinity". NEGATIVE_INFINITY Property.NEGATIVE_INFINITY) func1() else file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. the variable smallNumber is assigned a value that is smaller than the minimum value. anything multiplied by infinity is infinity. var smallNumber = -Number.MAX_VALUE*10 if (smallNumber == Number. and anything divided by infinity is zero.0 Tainted? No Description This value behaves mathematically like an infinity. Syntax Number. When the if statement executes.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Because NEGATIVE_INFINITY is a constant.

NaN. If it does. This property has a value only if data tainting is enabled. Examples The following example determines whether history. Syntax history. next is a read-only property.indexOf("NETSCAPE.0 Tainted? Yes Description The next property reflects the URL that would be used if the user chose Forward from the Go menu. next has no value.next. POSITIVE_INFINITY properties next Property.htm func2() See also MAX_VALUE.next) } file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. the function myFunction is called.COM".COM") != -1) { myFunction(history. MIN_VALUE.next contains the string "NETSCAPE. if (history. if data tainting is not enabled.next Property of history object Implemented in Navigator 3. A string specifying the complete URL of the next history entry.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm (17 of 64) [30/08/2003 9:34:26 PM] .

propertyName is one of the properties listed below. you will rarely need to create a Number file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. previous properties.htm See also current. positive and negative infinity. which represent the largest and smallest representable numbers. Most likely. numberObjectName is either the name of an existing Number object or a property of an existing object. The Number object is an object wrapper for primitive numeric values. The primary uses for the Number object are: q q To access its constant properties. When using Number properties. To create numeric objects that you can add properties to. and the Not-a-Number value.0 Description The Number object is a built-in JavaScript object. "Using data tainting for security" Number Object. Property of None Implemented in Navigator 3.propertyName Parameters numberObjectName is either the name of a new object or a property of an existing object. Lets you work with numeric values. Syntax To create a Number object: numberObjectName = new Number() To use a Number object: numberObjectName.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm (18 of 64) [30/08/2003 9:34:26 PM] .

NaN Note that these properties are properties of the Number() constructor itself.MAX_VALUE smallestNum = Number. returned on overflow POSITIVE_INFINITY prototype Special negative infinite value.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Then a value is assigned to the myNum object's description property. Properties The Number object has the following properties: Property MAX_VALUE MIN_VALUE NaN Description The largest representable number The smallest representable number Special "not a number" value NEGATIVE_INFINITY Special infinite value.htm object. The following example creates a Number object. not of individual Number objects.htm (19 of 64) [30/08/2003 9:34:26 PM] .MIN_VALUE infiniteNum = Number.description="wind speed" file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Methods q q q eval toString valueOf Event handlers None. myNum. then adds a description property to all Number objects. Example 2. The following example uses the Number object's properties to assign values to several numeric variables: biggestNum = Number. returned on overflow Lets you add a properties to a Number object.NEGATIVE_INFINITY notANum = Number.description=null myNum.prototype. Examples Example 1.POSITIVE_INFINITY negInfiniteNum = Number. myNum = new Number(65) Number.

gif" onAbort="alert('You didn\'t get to see the image!')"> See also onError. Event handler of Image Implemented in Navigator 3. and framesets. the onBlur event handler specifies JavaScript code to execute when a window loses focus. For windows.htm onAbort Event handler. Note file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. onLoad event handlers onBlur Event handler. The blur event can result from a blur method or from the user clicking the mouse on another object or window or tabbing with the keyboard. The onBlur event handler executes JavaScript code when a blur event occurs.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. The onAbort event handler executes JavaScript code when an abort event occurs. A frame's onBlur event handler overrides an onBlur event handler in the <BODY> tag of the document loaded into frame. An abort event occurs when the user aborts the loading of an image (for example by clicking a link or clicking the Stop button). frames. A blur event occurs when a form element loses focus or when a window or frame loses focus.htm (20 of 64) [30/08/2003 9:34:26 PM] . an onAbort handler in an Image object displays a message when the user aborts the image load: <IMG NAME="aircraft" SRC="f15e. See the relevant objects for the onAbort syntax.0 Examples In the following example.

Checkbox. but is implemented differently.bgColor='antiquewhite'"> Example 3: Change the background color of a frame.50%" COLS="40%. Password object. See the relevant objects for the onBlur syntax.value)"> Example 2: Change the background color of a window. FileUpload. window object Implemented in q q Navigator 2. the onFocus event handler changes the frame's background color to "antiquewhite". For information on using new to specify a string of JavaScript file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.bgColor='lightgrey'" onFocus="document. the onBlur event handler calls the required function to confirm that userName has a legal value. The following example creates four frames. not the document. a window's onBlur and onFocus event handlers change the window's background color depending on whether the window has focus. When a user attempts to leave the field. Event handler of Button object. The frame that loses focus is changed to "lightgrey". Text object. choose Release Notes from the Help menu). Textarea object. all frames are "lightgrey". In the following example. Reset. Select object.html NAME="frame4"> </FRAMESET> The following code has the same effect as the previous code. Note that the onBlur and onFocus event handlers are within the <BODY> tag. FileUpload object. The onBlur and onFocus event handlers for the frame are specified by setting the onblur and onfocus properties. <FRAMESET ROWS="50%. In the following example. <INPUT TYPE="text" VALUE="" NAME="userName" onBlur="required(this. When the document loads. Submit object. placing an onBlur event handler in a <FRAMESET> tag has no effect. Password. The source for each frame. Radio object. Frame. Radio.html has the <BODY> tag with the onBlur and onFocus event handlers shown in Example 1.htm (21 of 64) [30/08/2003 9:34:26 PM] .0: event handler of Button. When the user clicks a frame. The onFocus and onBlur event handlers are associated with the frame.htm On some platforms.0 Navigator 3. Reset object. <BODY BGCOLOR="lightgrey" onBlur="document. onblur2. Checkbox object. not the <FRAME> tag.html NAME="frame2"> <FRAME SRC=onblur2. Submit. and window Examples Example 1: Validate form input. Frame object. userName is a required text field. Please see the release notes (after starting Netscape.html NAME="frame1"> <FRAME SRC=onblur2.60%"> <FRAME SRC=onblur2.html NAME="frame3"> <FRAME SRC=onblur2.

Text object. a window's onBlur event handler closes the window when the window loses focus.html NAME="frame2"> <FRAME SRC=onblur2.0 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm code to be compiled as a function. i < frames.htm (22 of 64) [30/08/2003 9:34:26 PM] .html NAME="frame1"> <FRAME SRC=onblur2.length. A change event occurs when a select. i++) { frames[i]. See the relevant objects for the onChange syntax. text. Select object. The onChange event handler executes JavaScript code when a change event occurs.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.bgColor='antiquewhite'") frames[i].60%" onLoad=setUpHandlers()> <FRAME SRC=onblur2. or textarea field loses focus and its value has been modified. Use the onChange event handler to validate data after it is modified by a user. <BODY onBlur="window.onblur=new Function("document. Textarea object Implemented in q Navigator 2. onFocus event handlers onChange Event handler. Event handler of FileUpload object. see the Function object.close()"> This is some text </BODY> See also onChange.html NAME="frame4"> </FRAMESET> Example 4: Close a window.50%" COLS="40%.html NAME="frame3"> <FRAME SRC=onblur2. In the following example.bgColor='lightgrey'") } } </SCRIPT> <FRAMESET ROWS="50%.onfocus=new Function("document. <SCRIPT> function setUpHandlers() { for (var i = 0.

Checkbox object. links. reset buttons. the following code creates a hyperlink that.netscape. <INPUT TYPE="text" VALUE="" NAME="userName" onChange="checkValue(this. For example. When a user changes the text and leaves the field. <A HREF = "http://home. Event handler of Button object. For checkboxes. userName is a text field. The onClick event handler executes JavaScript code when a click event occurs. radio buttons. Submit object Implemented in q Navigator 2. onFocus event handlers onClick Event handler. Reset object. Please see the release notes (after starting Netscape.htm q Navigator 3. the onChange event handler calls the checkValue function to confirm that userName has a legal value. Link object. See the relevant objects for the onClick syntax.com/" onClick="return confirm('Load Netscape home page?')">Netscape</A> Returning false in an onClick event handler for a button has no effect. Note On some platforms.value)"> See also onBlur.0: event handler of FileUpload Examples In the following example. Radio object. displays a confirm dialog box. returning false in an onClick event handler for a reset button has no effect. choose Release Notes from the Help menu).file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. and submit buttons. the onClick event handler can return false to cancel the action normally associated with a click event. when clicked. the page specified by the hyperlink is not loaded. A click event occurs when an object on a form is clicked.htm (23 of 64) [30/08/2003 9:34:26 PM] .0 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. If the user clicks the hyperlink and then chooses cancel.

the onClick event handler returns false and the checkbox is not checked. an onError event handler would not intercept that message. The onError event handler executes JavaScript code when an error event occurs.html does not exist. return true"> Go!</A> In the above example. Are you sure?')"> Remove files onError Event handler. an error event is triggered by a bad URL within an <IMG> tag or by corrupted image data.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. the keyword this refers to the current object.href='notThere. If the user chooses Cancel.form refers to the form containing the button. suppose you have created a JavaScript function called pickRandomURL that lets you select a URL at random. An error event occurs only when a JavaScript syntax or runtime error occurs. <INPUT TYPE="checkbox" NAME="check1" VALUE="check1" onClick="return confirm('This purges all your files. For another example. Suppose you have created a JavaScript function called compute. in this case. the Calculate button.href=pickRandomURL()" onMouseOver="window. as shown in the following example: <A HREF="" onClick="this. The following example creates a checkbox with an onClick event handler. Example 2: Cancel the checking of a checkbox. You can use the onClick event handler of a link to specify a value for the HREF attribute of the <A> tag dynamically. not when a Navigator error occurs.htm q Navigator 3. An error event occurs when the loading of a document or image causes an error. if you try set window. as follows: <INPUT TYPE="button" VALUE="Calculate" onClick="compute(this.location.0: added the ability to return false to cancel the action associated with a click event Examples Example 1: Call a function when a user clicks a button. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. The construct this. The event handler displays a confirm that warns the user that checking the checkbox purges all files. the resulting error message is a Navigator error message.form)"> In the preceding example. you must return true to set the window.html' and notThere. therefore. However.htm (24 of 64) [30/08/2003 9:34:26 PM] . You can execute the compute function when the user clicks a button by calling the function in the onClick event handler.status property in the onMouseOver event handler.status='Pick a random URL'. the onMouseOver event handler specifies a custom message for the Navigator status bar when the user places the mouse pointer over the Go! anchor. As this example shows. For example.

See Example 3 below. and line number of the offending line). <IMG NAME="imageBad1" SRC="corrupt.htm (25 of 64) [30/08/2003 9:34:26 PM] . Event handler of Image object. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Setting window.gif" ALIGN="left" BORDER="2"> However. If you write an error-handling function. The onError event handler can be any of the following: q q q null to suppress all JavaScript error dialogs.htm window. Therefore. the handler would execute if the image had an error.onerror. <SCRIPT> window. you must spell it all lowercase and set it in a <SCRIPT> tag. the function must return true. including those for the Image object. the code onError="null" suppresses error messages if errors occur when the image loads. not just the Image object. you have three options for reporting errors: q q q Trace errors but let the standard JavaScript dialog report them (use an error handling function that returns false or does not return a value) Report errors yourself and disable the standard error dialog (use an error handling function that returns true) Turn off all error reporting (set the onError event handler to null) See the relevant objects for the onError syntax. window object Implemented in Navigator 3. In the following <IMG> tag. This suppresses all JavaScript error messages. not in other windows. The following code assigns null to the onError handler for the entire window.gif" ALIGN="left" BORDER="2" onError="null"> Example 2: Null event handler for a window.onerror to null means your users won't see JavaScript errors caused by your own code.onerror=null </SCRIPT> <IMG NAME="imageBad1" SRC="corrupt. The name of a function that handles errors (arguments are message text. A variable or property that contains null or a valid function reference. To suppress the standard JavaScript error dialog.0 Examples Example 1: Null event handler. The onError event handler for windows cannot be expressed in HTML.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. URL. if the Image object has a custom onError event handler.onerror applies only to errors that occur in the window containing window.

The function uses three arrays to store the message. <SCRIPT> window.document.writeln('<B>Error in file:</B> ' + urlArray[i] + '<BR>') win2.document.document.length.onerror=null suppresses JavaScript error messages. URL. function testErrorFunction() { testErrorFunction().length] = msg urlArray[urlArray.onerror = null.length] = lno return true } function displayErrors() { win2=window. When the user clicks the Display Error Report button. and line number for each error. the code would cause a stack overflow error because of infinite recursion. i++) { win2.") } </SCRIPT> <IMG NAME="imageBad1" SRC="corrupt.'scrollbars=yes') win2. the displayErrors function opens a window and creates an error report in that window. url. lno) { msgArray[msgArray.gif" ALIGN="left" BORDER="2" onError="myErrorFunc()"> In the following example.document.writeln('<B>Line number:</B> ' + lnoArray[i] + '<BR>') win2.document.open(''. Without onerror=null.writeln('<B>Error Report</B><P>') for (var i=0. not onError event handlers. window. } </SCRIPT> <BODY onload="testErrorFunction()"> test message </BODY> Example 3: Error handling function.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. <SCRIPT> window.close() file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm (26 of 64) [30/08/2003 9:34:26 PM] . The following example defines a function. myOnError.'window2'.writeln('<B>Message:</B> ' + msgArray[i] + '<P>') } win2.onerror=null function myErrorFunc() { alert("The image had a nasty error. i < msgArray. <SCRIPT> window. that intercepts JavaScript errors.length] = url lnoArray[lnoArray.htm This is because window.onerror=null suppresses all error reporting.onerror = myOnError msgArray = new Array() urlArray = new Array() lnoArray = new Array() function myOnError(msg. Note that the function returns true to suppress the standard JavaScript error dialog.

onLoad event handlers onFocus file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm } </SCRIPT> <BODY onload="noSuchFunction()"> <FORM> <BR><INPUT TYPE="button" VALUE="This button has a syntax error" onClick="alert('unterminated string)"> <P><INPUT TYPE="button" VALUE="Display Error Report" onClick="displayErrors()"> </FORM> This example produces the following output: Error Report Error in file: file:///c%7C/temp/onerror. the onError event handler calls the function badImage if errors occur when the image loads.html Line number: 34 Message: unterminated string literal Error in file: file:///c%7C/temp/onerror.html Line number: 30 Message: noSuchFunction is not defined Example 4: Event handler calls a function.htm (27 of 64) [30/08/2003 9:34:26 PM] .') } </SCRIPT> <FORM> <IMG NAME="imageBad2" SRC="orca.name + ' did not load properly.gif" ALIGN="left" BORDER="2" onError="badImage(this)"> </FORM> See also onAbort.html Line number: 34 Message: missing ) after argument list Error in file: file:///c%7C/temp/onerror.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. In the following <IMG> tag. <SCRIPT> function badImage(theImage) { alert('Error: ' + theImage.

Radio. Submit. placing an onFocus event handler in a <FRAMESET> tag has no effect. Frame. A frame's onFocus event handler overrides an onFocus event handler in the <BODY> tag of the document loaded into frame. not a focus event. the underlying window gains focus again and produces another focus event. The focus event can result from a focus method or from the user clicking the mouse on an object or window or tabbing with the keyboard. Text object. Event handler of Button object. See also onBlur. Radio object. Submit object. Please see the release notes (after starting Netscape. frame. window object Implemented in q q Navigator 2. or frameset receives focus or when a form element receives input focus. Checkbox. choose Release Notes from the Help menu). Reset. Textarea object. Note that placing an alert in an onFocus event handler results in recurrent alerts: when you press OK to dismiss the alert. FileUpload object. Frame object. See the relevant objects for the onFocus syntax. FileUpload. <INPUT TYPE="textarea" VALUE="" NAME="valueField" onFocus="valueCheck()"> See also the examples for the onBlur event handler. Selecting within a field results in a select event. The onFocus event handler executes JavaScript code when a focus event occurs.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. A focus event occurs when a window. Checkbox object. onChange event handlers onLoad file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm Event handler.htm (28 of 64) [30/08/2003 9:34:26 PM] . and window Examples The following example uses an onFocus handler in the valueField Textarea object to call the valueCheck function. Select object.0 Navigator 3.0: event handler of Button. Password object. Reset object. Note On some platforms. Password.

the alert displays the image name. In the following example. A load event occurs when Navigator finishes loading a window or all frames within a <FRAMESET> tag. In a FRAMESET and FRAME relationship. the onLoad event handler indicates the script to execute when an image is displayed. and the event handler executes once for each loop. the alert displays a message without the image name.alert("Welcome to the Brave New World home page!")> Example 2: Display alert when image loads.onload=displayAlert file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. then display them one by one in the same Image object by setting the object's src property. For the image created with the Image() constructor. which displays an alert. The onLoad event handler executes JavaScript code when a load event occurs. You can use the onLoad event handler to create a JavaScript animation by repeatedly setting the src property of an Image object. For images. each loop of the animation triggers the onLoad event. one with the Image() constructor and one with the <IMG> tag. for example. <BODY onLoad=".50) imageA. and it cannot specify parameters for the displayAlert function. the onLoad event handler executes every time an image is displayed. Event handler of Image object.">. Each Image object has an onLoad event handler that calls the displayAlert function. Do not confuse displaying an image with loading an image. the onLoad event handler displays a greeting message after a Web page is loaded. Use the onLoad event handler within either the BODY or the <FRAMESET> tag. an onLoad event within a frame (placed in the <BODY> tag) occurs before an onLoad event within the FRAMESET (placed in the <FRAMESET> tag). window object Implemented in q q Navigator 2.0: event handler of Image Examples Example 1: Display message when page loads. <SCRIPT> imageA = new Image(50.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. This is because the onLoad handler for an object created with the Image() constructor must be the name of a function. If you change the image displayed in this way. For the image created with the <IMG> tag. See the Image object for information.0 Navigator 3. The following example creates two Image objects. You can load several images. <BODY onLoad="window.htm (29 of 64) [30/08/2003 9:34:26 PM] . not just when the image is loaded into memory.. If you specify an onLoad event handler for an Image object that displays a looping GIF animation (multi-image GIF).htm Event handler..

Notice that the changeAnimation function does not call itself after changing the src property of the Image object.src="cyanball. the first file is again displayed. The following example displays an image.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Each animation is displayed in sequence in one Image object. !anim1.html is displayed.gif" BORDER=0 ALIGN="top" onLoad="changeAnimation(this)"> See also the examples for the Image object. The following example uses an onLoad event handler to rotate the display of six GIF animations. <SCRIPT> var whichImage=0 var maxImages=5 function changeAnimation(theImage) { ++whichImage if (whichImage <= maxImages) { var imageName="!anim" + whichImage + ". To see the value of cycles. <SCRIPT> var cycles=0 </SCRIPT> <IMG ALIGN="top" SRC="birdie.htm (30 of 64) [30/08/2003 9:34:26 PM] .gif" function displayAlert(theImage) { if (theImage==null) { alert('An image loaded') } else alert(theImage. that is a looping GIF animation. the image's onLoad event handler is triggered and the changeAnimation function is called. When the document loads.')"> Example 4: Change GIF animation displayed.name + ' has been loaded. !anim0.gif" ALIGN="top" onLoad=displayAlert(this)><BR> Example 3: Looping GIF animation.gif" theImage. the onLoad event handler causes the next file.html. completes.html. the user clicks the button labeled Count Loops. After the last animation.gif.') } </SCRIPT> <IMG NAME="imageB" SRC="greenball. The onLoad event handler for the image increments the variable cycles.htm imageA. which keeps track of the number of times the animation has looped.gif" BORDER=0 onLoad="++cycles"> <INPUT TYPE="button" VALUE="Count Loops" onClick="alert('The animation has looped ' + cycles + ' times. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. birdie. This is because when the src property changes. When that animation completes. !anim5. to load in place of the first file.src=imageName } else { whichImage=-1 return } } </SCRIPT> <IMG NAME="changingAnimation" SRC="!anim0.

then onMouseOver for the second. onError.htm See also onAbort.0 Examples See the examples for the Link object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. If the mouse moves from one area into another in a client-side image map. The onMouseOut event handler executes JavaScript code when a mouseOut event occurs. Link object Implemented in Navigator 3. onUnload event handlers onMouseOut Event handler. A mouseOver event occurs once each time the mouse pointer moves over an object or area from outside file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. A mouseOut event occurs each time the mouse pointer leaves an area (client-side image map) or link from inside that area or link. You must return true within the event handler if you want to set the status or defaultStatus properties with the onMouseOver event handler. Event handler of Area object (see Link object).htm (31 of 64) [30/08/2003 9:34:26 PM] . you'll get onMouseOut for the first area. See also onMouseOver event handler onMouseOver Event handler. Area objects that use the onMouseOut event handler must include the HREF attribute within the <AREA> tag. See the relevant objects for the onMouseOut syntax.

See the relevant objects for the onMouseOver syntax. return true"> Click me</A> See onClick for an example of using onMouseOver when the <A> tag's HREF attribute is set dynamically. See also the examples for the Link object.status='Click this if you dare!'. In the following example. you'll get onMouseOut for the first area.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q." <A HREF="http://home.com/" onMouseOver="window.0: event handler of Area Examples By default. The onReset event handler executes JavaScript code when a reset event occurs. The onMouseOver event handler executes JavaScript code when a mouseOver event occurs. Link object Implemented in q q Navigator 2. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Area objects that use the onMouseOver event handler must include the HREF attribute within the <AREA> tag. If the mouse moves from one area into another in a client-side image map. then onMouseOver for the second.htm that object or area. the onMouseOver event handler provides the custom message "Click this if you dare. the HREF value of an anchor displays in the status bar at the bottom of the Navigator when a user places the mouse pointer over the anchor. Event handler of Area object (see Link object).netscape. A reset event occurs when a user resets a form (clicks a Reset button).htm (32 of 64) [30/08/2003 9:34:26 PM] .0 Navigator 3. You must return true within the event handler if you want to set the status or defaultStatus properties with the onMouseOver event handler. See also onMouseOut event handler onReset Event handler.

The onSelect event handler executes JavaScript code when a select event occurs. the original value of "CA" is restored. Event handler of Form object Implemented in Navigator 3.htm See the relevant objects for the onReset syntax. <FORM NAME="form1" onReset="alert('Defaults have been restored.htm (33 of 64) [30/08/2003 9:34:26 PM] . Event handler of Text object.0 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.0 Examples The following example displays a Text object with the default value "CA" and a reset button. If the user types a state abbreviation in the Text object and then clicks the reset button. Reset object onSelect Event handler. A select event occurs when a user selects some of the text within a text or textarea field.')"> State: <INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2"><P> <INPUT TYPE="reset" VALUE="Clear Form" NAME="reset1"> </FORM> See also reset method. The form's onReset event handler displays a message indicating that defaults have been restored.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Textarea object Implemented in Navigator 2. See the relevant objects for the onSelect syntax.

the form is submitted.htm Examples The following example uses an onSelect handler in the valueField Text object to call the selectState function. </FORM> See also the examples for the Form object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. the onSubmit event handler calls the validate function to evaluate the data being submitted. See also Submit object. <FORM onSubmit="return validate(this)"> . If the data is valid. The onSubmit event handler executes JavaScript code when a submit event occurs. Any other returned value lets the form submit. to do so. otherwise. A submit event occurs when a user submits a form. <INPUT TYPE="text" VALUE="" NAME="valueField" onSelect="selectState()"> onSubmit Event handler. Event handler of Form object Implemented in Navigator 2. the form is not submitted.0 Examples In the following example. If you omit the return statement.. You can use the onSubmit event handler to prevent a form from being submitted. put a return statement that returns false in the event handler.htm (34 of 64) [30/08/2003 9:34:26 PM] . submit method file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. the form is submitted. See the relevant objects for the onSubmit syntax..

<BODY onUnload=". for example. Opens a stream to collect the output of write or writeln methods.open("text/html".. In a frameset and frame relationship.0 Examples In the following example.. An unload event occurs when you exit a document. Use the onUnload event handler within either the BODY or the <FRAMESET> tag.]document.">. an onUnload event within a frame (placed in the <BODY> tag) occurs before an onUnload event within the frameset (placed in the <FRAMESET> tag). Event handler of window object Implemented in Navigator 2. the onUnload event handler calls the cleanUp function to perform some shutdown processing when the user exits a Web page: <BODY onUnload="cleanUp()"> See also onLoad event handler open (document object) Method. The onUnload event handler executes JavaScript code when an unload event occurs.open(["mimeType"]) [windowReference.htm (35 of 64) [30/08/2003 9:34:27 PM] . Syntax document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm onUnload Event handler."replace") Parameters file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.

"replace" causes the new document to reuse the history entry that the previous document used. document.open() or document. as described in the window object. After using document.0 Navigator 3. When you specify "replace" while opening a document.htm (36 of 64) [30/08/2003 9:34:27 PM] . End the stream by using the document.0: added "replace" parameter. text/html is the default. For example.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. In Navigator 3. Using "replace" The "replace" keyword causes the new document to reuse the history entry that the previous document used. If a document exists in the target window. If the mimeType is text or image.0.open() or document. If you do not specify a mimeType. issue document. The close method causes text or images that were sent to layout to display. the target window's history length is not incremented even after you write and close.open("text/html") clears the current document if it has finished loading.open() again when you want to begin another output stream. When you file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm mimeType is an optional argument that specifies the type of document to which you are writing.open("text/html") clears the current document if it has finished loading Description The open method opens a stream to collect the output of write or writeln methods. the open method clears it.close() method. document. the stream is opened to a plug-in. and "application/x-director" loads the Macromedia Shockwave plug-in. otherwise. windowReference is a valid way of referring to a window. image/x-bitmap specifies a document with encoded bytes constituting a bitmap header and pixel data. text/plain specifies a document containing plain ASCII text with end-of-line characters to delimit displayed lines. Method of document Implemented in q q Navigator 2. This is because this type of open call writes a default <BASE HREF=> tag so you can generate relative URLs based on the generating script's document base.close(). plugIn loads the specified plug-in and uses it as the destination for write and writeln methods. Plug-in MIME types are only valid if the user has installed the required plugin software. q q q q q q text/html specifies a document containing ASCII text with HTML formatting. image/jpeg specifies a document with encoded bytes constituting a JPEG header and pixel data. "xworld/vrml" loads the VR Scout VRML plug-in from Chaco Communications. the stream is opened to layout. image/gif specifies a document with encoded bytes constituting a GIF header and pixel data.

document. "width=1.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. After document. 'toolbar=yes. replacing the current history entry. the target window's history length is not incremented even after you write and close.htm specify "replace" while opening a document. Examples Example 1.close() } The following code creates the msgWindow window and calls the function: msgWindow=window. The following function calls document.document. The HTML code in the write methods is written to msgWindow. replacing the history entry for the blank URL.length is " + msgWindow.write("<P>" + myString) msgWindow. the probePlugIn function determines whether a user has the Shockwave plug-in installed: function probePlugIn(mimeType) { var havePlugIn = false var tiny = window.document.htm (37 of 64) [30/08/2003 9:34:27 PM] .document.document.height=1") if (tiny != null) { file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. the write method typically generates HTML for the window.height=300') windowWriter2() Example 3. and the user can press the Back button and back up until the frame is empty."replace") executes. The following function calls document. history.write("<P>history. In the following example.close() } Example 2.write("<P>" + myString) msgWindow. the generated HTML has its own history entry.open with the "replace" keyword to open a stream before issuing write methods."replace") msgWindow. world!" msgWindow.width=400.open("text/html". After "replace" is specified.current for the target window is the URL of document that executed document.open to open a stream before issuing a write method: function windowWriter1() { var myString = "Hello.document.history.length) msgWindow. world!" msgWindow.''.open(''. "replace" is typically used on a window that has a blank document or an "about:blank" URL. function windowWriter2() { var myString = "Hello. Take care when using generated HTML on a window with a blank URL.scrollbars=yes.open() msgWindow.document.open. "teensy". The history length of msgWindow is not incremented.open("text/html". If you do not specify "replace".open("".

open(mimeType) != null) havePlugIn = true tiny. windowName can contain only alphanumeric or underscore (_) characters.htm (38 of 64) [30/08/2003 9:34:27 PM] . "windowName".close() } return havePlugIn } var haveShockwavePlugIn = probePlugIn("application/x-director") See also close (document object). URL specifies the URL to open in the new window. See the location object for a description of the URL components. Do not put spaces between the options. replace. Syntax [windowVar = ][window].htm if (tiny.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. methods. Separate options with a comma.open("URL". ["windowFeatures"]) Parameters windowVar is the name of a new window. write. windowFeatures is a comma-separated list of any of the following options and values: toolbar[=yes|no]|[=1|0] location[=yes|no]|[=1|0] directories[=yes|no]|[=1|0] status[=yes|no]|[=1|0] menubar[=yes|no]|[=1|0] scrollbars[=yes|no]|[=1|0] resizable[=yes|no]|[=1|0] width=pixels height=pixels You may use any subset of these options. windowName is the window name to use in the TARGET attribute of a FORM or <A> tag. Opens a new web browser window.document. The windowFeatures are: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. writeln methods open (window object) Method. Use this variable when referring to a window's properties. reload. and containership.

a call to open() without specifying an object name is equivalent to document. directories creates the standard Navigator directory buttons. if true. such as What's New and What's Cool. but not load anything into it. location creates a Location entry field. and if you pass the empty string for the URL. Method of window object Implemented in Navigator 2. if true. if true. similar to choosing New Web Browser from the File menu of the Navigator."displayWindow". In event handlers. If windowName does not specify an existing window and you do not specify windowFeatures. a new. windowFeatures is an optional. The URL argument specifies the URL contained by the new window.htm (39 of 64) [30/08/2003 9:34:27 PM] .open() instead of simply using open(). if true. After a window is open. If URL is an empty string. you will get a reference to the existing window. width specifies the width of the window in pixels.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. if true. the windowOpener function opens a window and uses write methods to display a message: function windowOpener() { msgWindow=window.document.0 Description The open method opens a new Web browser window on the client. status creates the status bar at the bottom of the window. "messageWindow"."menubar=yes") msgWindow. scrollbars creates horizontal and vertical scrollbars when the document grows larger than the window dimensions. resizable allows a user to resize the window. If you specify any item in windowFeatures. empty window is created. all other Boolean windowFeatures are false unless you explicitly specify them. with buttons such as Back and Forward. You can. then look for properties in the window.htm q q q q q q q q q toolbar creates the standard Navigator toolbar. if true. you must specify window. For example.open("". all Boolean windowFeatures are true by default. or as yes or 1. you cannot use JavaScript to change the windowFeatures. "toolbar") and open("". Examples In the following example. open("". You can use open on an existing window.write file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. if true.open(). The Boolean windowFeatures options are set to true if they are specified without values. Due to the scoping of static objects in JavaScript. height specifies the height of the window in pixels. "toolbar=1") both set the toolbar option to true. "messageWindow". comma-separated list of options for the new window. menubar creates the menu at the top of the window. for example.

opener Property of window object Implemented in Navigator 3. world!</B></BIG></CENTER>") } The following is an onClick event handler that opens a new client window displaying the content specified in the file sesame.height=300')"> </FORM> Notice the use of single quotes (') inside the onClick event handler. The window opens with the specified option settings.open ('sesame.document.html.htm (40 of 64) [30/08/2003 9:34:27 PM] .htm ("<HEAD><TITLE>Message window</TITLE></HEAD>") msgWindow.status=yes. <FORM NAME="myform"> <INPUT TYPE="button" NAME="Button1" VALUE="Open Sesame!" onClick="window. See also close (window object) method opener Property.width=300.write ("<CENTER><BIG><B>Hello. all other options are false because they are not specified. Specifies the window of the calling document when a window is opened using the open method. 'newWin'. Syntax window.html'.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. 'scrollbars=yes.0 Tainted? No Description file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.

see the Select object.htm When a source document opens a destination window by calling the open method. However. The following code closes the window that opened the current window.opener.close() Example 2: Evaluate the name of the opener.htm (41 of 64) [30/08/2003 9:34:27 PM] . window. When the opener window closes.name) Example 3: Change the value of opener. the opener property specifies the window of the source document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.opener. window.opener=null Example 4: Change a property of the opener.document. The following code changes the value of the opener property to null. This property persists across document unload in the opened window. you cannot close the opener window as shown in Example 1. After this code executes. An array corresponding to options in a Select object (OPTION tags) in source order.opener. options Property. The following code changes the background color of the window specified by the opener property.name then evaluates to undefined. window.write("<BR>opener property is " + window. opener is unchanged.opener. For information. A Select object option created using the Option() constructor. You can change the opener property at any time. Examples Example 1: Close the opener. window. See the Select object. open (window object) methods Option Object.bgColor='bisque' See also close (window object). A window can determine the name of its opener as follows: document. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Evaluate the opener property from the destination window.

propertyName parent.frames[3]. frameName and frames[index] are ways to refer to frames. or parent property when the calling parent refers to a Frame object.0 Tainted? No Description The parent property refers to the FRAMESET window of a frame. or parent property when the calling parent refers to a window object.parent to refer to the "grandparent" frame or window when a <FRAMESET> tag is nested file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. You can use parent.frames[index]. methodName is any method associated with the window object. propertyName is the length. if the fourth frame in a set has NAME="homeFrame.frameName parent.methodName parent.frameName or parent. name. status. length. Child frames within a frameset refer to sibling frames by using "parent" in place of the window name as follows: parent. window object Implemented in Navigator 2. Property of Frame object. name. 2.htm (42 of 64) [30/08/2003 9:34:27 PM] . 3. 4. parent. For example.htm parent Property." sibling frames can refer to that frame using parent.frames[index] Parameters propertyName is the defaultStatus.homeFrame or parent.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. The parent property is a synonym for a window or frame whose frameset contains the current frame. Syntax 1.

The parent property is read-only.htm within a child frame. but for general use.0 Description The parse method takes a date string (such as "Dec 25. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. 1970. "Mon. local time.htm (43 of 64) [30/08/2003 9:34:27 PM] . The value of the parent property is <object nameAttribute> where nameAttribute is the NAME attribute if the parent is a frame. Given a string representing a time. parse returns the time value. use a time-zone offset. If you do not specify a time zone." It understands the continental US time-zone abbreviations. It accepts the IETF standard date syntax: "Mon. 00:00:00 (local time). Syntax Date. 25 Dec 1995 13:30:00 GMT+0430" (4 hours. parse Method. Method of Date Implemented in Navigator 2. GMT and UTC are considered equivalent. or an internal reference if the parent is a window. 30 minutes west of the Greenwich meridian). for example. This function is useful for setting date values based on string values.parse(dateString) Parameters dateString is a string representing a date or a property of an existing object. for example in conjunction with the setTime method and the Date object. Returns the number of milliseconds in a date string since January 1. 1995") and returns the number of milliseconds since January 1. 1970. Examples See the examples for the Frame object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. the local time zone is assumed. 00:00:00. 25 Dec 1995 13:30:00 GMT.

a string. Implemented in q q Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. If the first character cannot be converted to a number.0 Navigator 3. or an exponent. numeral (0-9). Examples If IPOdate is an existing Date object. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. In previous releases. parseFloat returns "NaN".parse("Aug 9. It is not a method associated with any object. a decimal point. If it encounters a character other than a sign ( + or -).setTime(Date. but is part of the language itself. Description The parseFloat function is a built-in JavaScript function.htm Because the parse function is a static method of Date. you always use it as Date. Syntax parseFloat(string) Parameters string is a string that represents the value you want to parse. parseFloat parses its argument.htm (44 of 64) [30/08/2003 9:34:27 PM] . then IPOdate.0: returns "NaN" on all platforms if the first character of the string specified in parseFloat(string) cannot be converted to a number. then it returns the value up to that point and ignores that character and all succeeding characters. and returns a floating point number. rather than as a method of a Date object you created.parse(). 1995")) See also UTC method parseFloat Function. it returned "NaN" on Solaris and Irix and zero on all other platforms. Parses a string argument and returns a floating point number.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. the operation results will also be "NaN.0 Navigator 3.0314E+2") var x = "3. it returned "NaN" on Solaris and Irix and zero on all other platforms. the "NaN" value is not a number in any radix. Syntax parseInt(string [. radix is an integer that represents the radix of the return value.0: returns "NaN" on all platforms if the first character of the string specified in parseInt(string) cannot be converted to a number.htm For arithmetic purposes." If "NaN" is passed on to arithmetic operations. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Implemented in q q Navigator 2.14") parseFloat("314e-2") parseFloat("0.radix]) Parameters string is a string that represents the value you want to parse. Parses a string argument and returns an integer of the specified radix or base.htm (45 of 64) [30/08/2003 9:34:27 PM] ." Examples The following examples all return 3. parseInt functions parseInt Function. You can call the isNaN function to determine if the result of parseFloat is "NaN. In previous releases.14" parseFloat(x) The following example returns "NaN": parseFloat("FF2") See also isNaN.14: parseFloat("3.

for hexadecimal numbers (base 16). a string. and so on.htm Description The parseInt function is a built-in JavaScript function.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. the following examples all return 17 because the input string begins with "0x. For example. It is not a method associated with any object. 8) parseInt("0x7"." If "NaN" is passed on to arithmetic operations. parseInt truncates numbers to integer values." the radix is eight (octal). but is part of the language itself. JavaScript assumes the following: q q q If the input string begins with "0x. the radix is 10 (decimal)." parseInt("0x11". For example. If the first character cannot be converted to a number. parseInt returns "NaN". the operation results will also be "NaN. You can call the isNaN function to determine if the result of parseInt is "NaN. 16) parseInt("17". 10) parseInt(15. and attempts to return an integer of the specified radix (base). a radix of 10 indicates to convert to a decimal number. 2) parseInt("15*3". 16) parseInt("1111". 8) parseInt("15". 10) Even though the radix is specified differently.htm (46 of 64) [30/08/2003 9:34:27 PM] . 8 octal. 16) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. For radixes above 10." the radix is 16 (hexadecimal). the "NaN" value is not a number in any radix." Examples The following examples all return 15: parseInt("F". it ignores it and all succeeding characters and returns the integer value parsed up to that point. If the input string begins with any other value. 10) parseInt("FFF". the letters of the alphabet indicate numerals greater than 9. 10) parseInt("FXX123". If the input string begins with "0.99. If the radix is not specified or is specified as zero. 16 hexadecimal. If parseInt encounters a character that is not a numeral in the specified radix. For arithmetic purposes. 10) The following examples all return "NaN": parseInt("Hello". A through F are used. The parseInt function parses its first argument.

Syntax To use a Password object's properties and methods: 1. valueOf method Password Object. 4.propertyName formName. 0) parseInt("0x11") See also isNaN. and you can use this name when indexing the elements array. 3.methodName(parameters) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.elements[index]. use standard HTML syntax: <INPUT TYPE="password" NAME="passwordName" [VALUE="textValue"] SIZE=integer [onBlur="handlerText"] [onFocus="handlerText"]> HTML attributes NAME="passwordName" specifies the name of the Password object.methodName(parameters) formName. SIZE=integer specifies the number of characters the Password object can accommodate without scrolling. You can access this value using the name property. You can access this value using the defaultValue property.propertyName passwordName. HTML syntax To define a Password object.htm parseInt("0x11". parseFloat functions.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm (47 of 64) [30/08/2003 9:34:27 PM] . 2. passwordName. When the user enters text into the field. VALUE="textValue" specifies the initial value of the Password object. A text field on an HTML form that conceals its value by displaying asterisks (*). asterisks (*) hide entries from view.elements[index].

Property of Form object Implemented in q q Navigator 2. formName is either the value of the NAME attribute of a Form object or an element in the forms array.0: added type property. If a user interactively modifies the value in a password field. Properties The Password object has the following properties: Property Description defaultValue Reflects the VALUE attribute form property Specifies the form containing the Password object name type Reflects the NAME attribute Reflects the TYPE attribute file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm Parameters passwordName is the value of the NAME attribute of a Password object. propertyName is one of the properties listed below. you cannot evaluate it accurately unless data tainting is enabled.htm (48 of 64) [30/08/2003 9:34:27 PM] . methodName is one of the methods listed below. added onBlur and onFocus event handlers Description A Password object on a form looks as follows: Enter your password: A Password object is a form element and must be defined within a <FORM> tag.0 Navigator 3. index is an integer representing a Password object on a form or the name of a Password object as specified by the NAME attribute. See "Using data tainting for security" and the value property.

A string specifying the url-path portion of the URL. links[index]. areaName.pathname 2. areaName is the value of the NAME attribute of an Area object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Syntax 1.htm (49 of 64) [30/08/2003 9:34:27 PM] . file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. location.pathname 3.pathname Parameters index is an integer representing a Link object or the name of a Link object as specified by the NAME attribute. Text object pathname Property.htm value Reflects the current value of the Password object's field Methods The Password object has the following methods: q q q blur eval focus q q q select method toString valueOf Event handlers q q onBlur onFocus Examples The following example creates a Password object with no default value: <B>Password:</B> <INPUT TYPE="password" NAME="password" VALUE="" SIZE=25> See also Form object.

0: property of Area Tainted? Yes Description The pathname property specifies a portion of the URL.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Link object. you must specify window. you will get an error. Examples See the examples for the href property. The ratio of the circumference of a circle to its diameter.location. protocol. location object Implemented in q q Navigator 2. which is a synonym for document.0 Navigator 3.14159. See Section 3. You can set the pathname property at any time. The pathname supplies the details of how the specified resource can be accessed. hostname.htm (50 of 64) [30/08/2003 9:34:27 PM] . search properties PI Property.URL.1 of RFC 1738 for complete information about the pathname. although it is safer to set the href property to change a location.location. host.htm Property of Area object (see Link object). a call to location without specifying an object name is equivalent to document. In event handlers. port. Due to the scoping of static objects in JavaScript. href. approximately 3. Syntax file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. See also hash.pathname instead of simply using location.pathname. If the pathname that you specify cannot be found in the current location.

LOG10E. A plug-in module installed on the client. Syntax To use a Plugin object: 1.0 Tainted? No Description Because PI is a constant. Examples The following function returns the value of pi: function getPi() { return Math.PI Property of Math Implemented in Navigator 2. LOG2E. LN2.PI } See also E. LN10. navigator.plugins[index]. navigator. SQRT1_2.mimeTypePropertyName file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm (51 of 64) [30/08/2003 9:34:27 PM] . SQRT2 properties Plugin Object.htm Math.plugins[pluginIndex][mimeTypeIndex].propertyName 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. it is a read-only property of Math.

description) The preceding code displays output similar to the following: myMimeType.description is '.description is QuickTime for Windows The Plugin object lets you dynamically determine which plug-ins are installed on the client. You can write scripts to display embedded plug-in data if the appropriate plug-in is installed.myMimeType. Implemented in Navigator 3.0 Description A Plugin object is a plug-in installed on the client. For example. You can access the MimeType objects using form 2 of the syntax. The Plugin object is a member of the plugins array. Each Plugin object is an array containing one element for each MIME type supported by the plug-in. The user can obtain a list of installed plug-ins by choosing About Plug-ins from the Help menu.writeln('myMimeType. Each element of the array is a MimeType object."<BR>") document. Property of The plugins array is a property of navigator. or display some alternative information such as images or text if not.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm Parameters index is an integer representing a plug-in installed on the client or a string containing the type of a Plugin object (from the type property). mimeTypePropertyName is a property of a MimeType object.plugins[0] myMimeType=myPlugin[0] document. myPlugin=navigator. mimeTypeIndex is either an integer representing a MIME type supported by the plug-in or a string containing the type of a MimeType object (from the type property).writeln('myMimeType.type is '. propertyName is one of the properties listed below.myMimeType. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. See MimeType for a list of properties.type is video/quicktime myMimeType. A plug-in is a software module that Navigator can invoke to display specialized types of embedded data within the browser.type.htm (52 of 64) [30/08/2003 9:34:27 PM] . the following code displays the type and description properties of the first Plugin object's first MimeType object.

Each element of the plugins array is a Plugin object. navigator. these plug-ins are reflected as navigator. Properties The Plugin object has the following properties: Property filename length name Description The name of the plug-in file on disk The number of elements in the plug-in's array of MimeType objects The name of the plug-in description A description supplied by the plug-in itself The plugins array has the following properties: Property Description length Reflects the number of plug-ins installed on the client Methods file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. For example.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.length index is an integer representing a plug-in installed on the client or a string containing the name of a Plugin object (from the name property).plugins[index] 2.length. Each Plugin object is an element in the plugins array.plugins[2]. navigator. so a Plugin object's array of MimeType objects can vary from platform to platform.plugins[0]="LiveAudio" has no effect. if three plug-ins are installed on the client. To use the plugins array: 1. the statement navigator. See the embeds array. navigator. To obtain the number of plug-ins installed on the client. and from user to user.htm Plug-ins can be platform dependent and configurable. Elements in the plugins array are read-only. The plugins array You can reference the Plugin objects installed on the client by using the plugins array. When you use the <EMBED> tag to generate output from a plug-in application.htm (53 of 64) [30/08/2003 9:34:27 PM] . and navigator.plugins[0]. Use the embeds array to reference plug-in instances created with <EMBED> tags.plugins. use the length property: navigator. This array contains an entry for each plug-in installed on the client in source order.plugins[1].plugins. you are not creating a Plugin object. For example.

filename.htm The Plugin object has the following methods: q q q eval toString valueOf The plugins array has the following methods: q refresh Event handlers None. The following code displays the message "LiveAudio is configured for audio/wav" if the LiveAudio plug-in is installed and is enabled for the "audio/wav" MIME type: var myPlugin = navigator. "<TH ALIGN=left>filename". then choose Document Source from the View menu.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. var myPluginName = navigator. The following code displays the name. To see the code Navigator uses for this report. choose About Plug-ins from the Help menu. Example 2.length Example 5. "<TH ALIGN=left>i". The following expression represents the number of MIME types that Shockwave can display: navigator. "<TH ALIGN=left>name".plugins["Shockwave"]. and length properties for each Plugin object on a client: document.htm (54 of 64) [30/08/2003 9:34:27 PM] .plugins["LiveAudio"].plugins["LiveAudio"].description Example 3. "<TH ALIGN=left>description". The following code assigns shorthand variables for the predefined LiveAudio properties.name var myPluginFile = navigator.writeln("<TABLE BORDER=1><TR VALIGN=TOP>".enabledPlugin == myPlugin) document. The user can obtain a list of installed plug-ins by choosing About Plug-ins from the Help menu.plugins["LiveAudio"] var myType = myPlugin["audio/wav"] if (myType && myType.plugins["LiveAudio"]. Examples Example 1.filename var myPluginDesc = navigator.writeln("LiveAudio is configured for audio/wav") Example 4. description.

plugins[i].file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.DLL v.navigator. "<TD>". avi plugin DLL plugins\npavi32.plugins[i].plugins[i].navigator. See the Plugin object for information.plugins.plugins[i]. "<TD>".1.DLL sound playing component 2 1 2 NPAVI32 Dynamic Link Library d:\nettools\netscape\nav30\Program\ NPAVI32.name.description.dll See also MimeType object. "<TD>".0 d:\nettools\netscape\nav30\Program\ LiveAudio .filename.navigator. embeds array plugins Property.htm "<TH ALIGN=left># of types</TR>") for (i=0.dll 3 Netscape Default Plugin d:\nettools\netscape\nav30\Program\ Null Plugin plugins\npnul32. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. "<TD>". i < navigator. i++) { document. Tainted? No port Property. A string specifying the communications port that the server uses for communications. An array of all plug-ins currently installed on the client.navigator.writeln("<TR VALIGN=TOP><TD>".length. "</TR>") } document.Netscape Navigator 7 plugins\NPAUDIO.i.0.length.writeln("</TABLE>") The preceding example displays output similar to the following: i name 0 QuickTime Plug-In 1 LiveAudio filename description # of types 1 d:\nettools\netscape\nav30\Program\ QuickTime Plug-In for Win32 plugins\NPQTW32.htm (55 of 64) [30/08/2003 9:34:27 PM] .

a call to location without specifying an object name is equivalent to document.1 of RFC 1738 for complete information about the port.port 3 areaName. you will get an error.location. You can set the port property at any time. links[index]. See Section 3.htm Syntax 1. When the port property is 80 (the default).port. location. If the port that you specify cannot be found in the current location.0: property of Area Tainted? Yes Description The port property specifies a portion of the URL.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. areaName is the value of the NAME attribute of an Area object. separated by a colon. it defaults to 80 on the server. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. The port property is a substring of the hostname property.port instead of simply using location. Due to the scoping of static objects in JavaScript.location.0 Navigator 3.URL.port Parameters index is an integer representing a Link object or the name of a Link object as specified by the NAME attribute. In event handlers. which is a synonym for document.htm (56 of 64) [30/08/2003 9:34:27 PM] . the host property is the same as the hostname property. location object Implemented in q q Navigator 2. Examples See the examples for the href property. you must specify window. If the port property is not specified. Link object.port 2. The hostname property is the concatenation of the host and port properties. Property of Area object (see Link object). although it is safer to set the href property to change a location.

bigNumber has the value "Infinity".POSITIVE_INFINITY Property of Number Implemented in Navigator 3. anything multiplied by infinity is infinity. search properties POSITIVE_INFINITY Property.0 Tainted? No Description This value behaves mathematically like an infinity. protocol. for example. Syntax Number.htm See also hash. var bigNumber = Number. Examples In the following example. pathname. host. so the func1 function is called. This value is represented as "Infinity". JavaScript does not have a literal for Infinity. A special numeric value representing infinity. href.htm (57 of 64) [30/08/2003 9:34:27 PM] . When the if statement executes. and anything divided by infinity is zero.MAX_VALUE * 10 if (bigNumber == Number.POSITIVE_INFINITY) func1() else file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. it is a read-only property of Number.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. hostname. Because POSITIVE_INFINITY is a constant. the variable bigNumber is assigned a value that is larger than the maximum value.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.htm (58 of 64) [30/08/2003 9:34:27 PM] . See also exp. NEGATIVE_INFINITY properties pow Method. NaN. Method of Math Implemented in Navigator 2. raisePower returns 49 (seven to the power of two).y) } If x equals seven and y equals two. log methods file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. exponent is any numeric expression or a property of an existing object. Returns base to the exponent power.y) { return Math.pow(base. baseexponent. Syntax Math.0 Examples function raisePower(x. that is.htm func2() See also MAX_VALUE. exponent) Parameters base is any numeric expression or a property of an existing object.pow(x. MIN_VALUE.

previous.htm previous Property.0 Tainted? Yes Description The previous property reflects the URL that would be used if the user chose Back from the Go menu.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. next properties. Syntax history. This property has a value only if data tainting is enabled. If it does. A string specifying the complete URL of the previous history entry. "Using data tainting for security" file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. previous has no value. Examples The following example determines whether history.COM") != -1) { myFunction(history.previous Property of history object Implemented in Navigator 3.previous) } See also current. if data tainting is not enabled.COM". previous is a read-only property.previous contains the string "NETSCAPE.indexOf("NETSCAPE. if (history.htm (59 of 64) [30/08/2003 9:34:27 PM] . the function myFunction is called.

Displays a Prompt dialog box with a message and an input field. inputDefault is a string. integer. windowReference.htm prompt Method. the string is displayed as the message. Method of window object Implemented in Navigator 2.prompt() is unnecessary. You cannot specify a title for a prompt dialog box. you do not need to specify a windowReference when you call it. [inputDefault]) Parameters message is any string or a property of an existing object.0 Description A prompt dialog box looks as follows: Click for sample prompt dialog box Use the prompt method to display a dialog box that receives user input. For example. but you can use the open method to create your own "prompt" dialog." Although prompt is a method of the window object. 12) See also file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. Syntax prompt(message. Examples prompt("Enter the number of cookies you want to order:".file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. or property of an existing object that represents the default value of the input field. the dialog box displays "<undefined>.htm (60 of 64) [30/08/2003 9:34:27 PM] . If you do not specify an initial value for inputDefault. See open (window object).

location. confirm methods protocol Property. If the protocol that you specify cannot be found in the current location.htm (61 of 64) [30/08/2003 9:34:27 PM] . In event handlers.protocol Parameters index is an integer representing a Link object or the name of a Link object as specified by the NAME attribute. Syntax 1.protocol 3 areaName. a protocol of "http:" specifies HyperText Transfer Protocol. A string specifying the beginning of the URL. Link object. links[index].protocol 2.protocol instead of simply using location. you will get an error. a call to location without specifying an file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. up to and including the first colon. Property of Area object (see Link object). and a protocol of "javascript:" specifies JavaScript code. Due to the scoping of static objects in JavaScript. areaName is the value of the NAME attribute of an Area object. although it is safer to set the href property to change a location.location. The protocol indicates the access method of the URL.protocol.0 Navigator 3.htm alert.0: property of Area Tainted? Yes Description The protocol property specifies a portion of the URL.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. You can set the protocol property at any time. For example. location object Implemented in q q Navigator 2. you must specify window.

search properties prototype Property. such as the following: q q q q q Array Boolean Date Function Image q q q q Number Select object option String User-defined objects (see "Creating new objects") Implemented in file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. href.prototype. See Section 2.htm object name is equivalent to document.htm (62 of 64) [30/08/2003 9:34:27 PM] . hostname. Defines a property that is shared by all objects of the specified type.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.URL. Property of prototype is a property of any object created with new. host. Syntax objectType.propertyName = value Parameters objectType is the name of a constructor or function specifying an object type.1 of RFC 1738 for complete information about the protocol. pathname. Examples See the examples for the href property. See also hash. value is the property value initially assigned for all objects of the specified objectType. which is a synonym for document. propertyName is the name of the property to be created.location. The protocol property represents the scheme name of the URL. port.

prototype.description="Started the daily grind" Examples Example 1: Add a property to a user-defined object.htm (63 of 64) [30/08/2003 9:34:27 PM] .prototype. even objects already created.description. For example.prototype refers to the prototype object for the Date() constructor.prototype. The following example uses the function Car to define a Car object type.wheels == 4) document. 1987) Car. even if the objects already exist. " wheels.wheels=4 adds the wheels property to all instances of the Car object. It then uses new to create myCar.17) Date.12. Date. The following example creates a method. The code Car. year) { this. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.description="The day you were born" After you set a property for the prototype.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q. The example then creates an alternate method and adds that to one of the String objects using the statement s1. you can create Date objects by using the Date() constructor and the new operator.make = make this. var today = new Date() var birthday = new Date(95. "Integra". model.") Example 2: Add a method to String objects.prototype. If you set a property for the prototype.wheels. The str_rep method of the remaining String objects is not altered.htm Navigator 3. All objects created with new String() then have that method. function Car(make. then all objects created with Date() will have the description property. myCar.description="Oh what a beautiful mornin\'" birthday. such as Date.write("The car myCar has ". an instance of the object. all subsequent objects created with Date() will have the property: startDate=new Date() startDate.description=null today. str_rep.rep = str_rep to add the method to all String objects.year = year } var myCar = new Car("Acura".wheels = 4 // no 3-wheelers please! if (myCar.model = model this.prototype. and uses the statement String.0 Tainted? No Description Use the prototype property to explicitly add properties to objects created with the new operator.rep = fake_rep.

rep(6)) // "cccccc" This example produces the following output: s1." } s1.rep(4) is " + s2.rep(1) is " + s1. s2.rep(2) is " + s3. The following code returns "zzz". t = this.write("<P>s1." document.htm (64 of 64) [30/08/2003 9:34:27 PM] .write("<BR>s3.write("<BR>s2.write("<BR>s3.toString() while (--n >= 0) s += t return s } String.rep(5) is " + s2.rep(1)) // "repeat a 1 times.rep(3) See also constructor property.htm var s1 = new String("a") var s2 = new String("b") var s3 = new String("c") // Create a repeat-string-N-times method for all String objects function str_rep(n) { var s = "".write("<BR>s2.rep(4) is bbbb s3.rep(1) is repeat a1 times.rep(3) is aaa s2. "Creating new objects" [Next reference file] file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.rep(4)) // "bbbb" document.rep(2)) // "cc" // Create an alternate method and assign it to only one String variable function fake_rep(n) { return "repeat " + this + n + " times.rep(2) is cc s1.prototype.rep(3)) // "aaa" document.rep(6) is cccccc The function in this example also works on String objects not created with the String() constructor.rep = str_rep // Display the results document.rep(5) is bbbbb s3.write("<P>s1.rep(5)) // "bbbbb" document.rep(3) is " + s1. "z".rep = fake_rep document.rep(6) is " + s3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_m-q.

htm [Previous reference file] Radio Object. This defaults to "on. HTML syntax To define a set of radio buttons.methodName(parameters) Parameters file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. VALUE="buttonValue" specifies a value that is returned to the server when the radio button is selected and the form is submitted. CHECKED specifies that the radio button is selected. The user can use a set of radio to choose one item from a list. 3.elements[index2]. radioName[index1].htm (1 of 17) [30/08/2003 9:34:28 PM] . textToDisplay specifies the label to display beside the radio button.methodName(parameters) formName.elements[index2].file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.propertyName formName. All radio buttons in a group have the same NAME attribute. Syntax To use a radio button's properties and methods: 1. and you can use this name when indexing the elements array. You can access this value using the defaultChecked property. You can access this value using the name property.propertyName radioName[index1]. 2. use standard HTML syntax with the addition of JavaScript event handlers: <INPUT TYPE="radio" NAME="radioName" VALUE="buttonValue" [CHECKED] [onBlur="handlerText"] [onClick="handlerText"] [onFocus="handlerText"]> textToDisplay HTML attributes NAME="radioName" specifies the name of the Radio object." You can access this value using the value property. 4. A set of radio buttons on an HTML form.

0 Navigator 3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. formName is either the value of the NAME attribute of a Form object or an element in the forms array.0: added type property. document. All radio buttons in a radio button group use the same name property.radioName[0] is the first. index1 is an integer representing a radio button in a Radio object. and so on. propertyName is one of the properties listed below. added blur and focus methods Description A Radio object on a form looks as follows: R&B Jazz Soul A Radio object is a form element and must be defined within a <FORM> tag. To access the individual radio buttons in your code.forms[0]. methodName is one of the methods listed below. Properties The Radio object has the following properties: Property checked Description Lets you programmatically select a radio button file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.htm radioName is the value of the NAME attribute of a Radio object.forms[0].radioName[1] is the second. index2 is an integer representing a radio button on a form. follow the object name with an index starting from zero. one for each button the same way you would for an array such as forms: document. Property of Form object Implemented in q q Navigator 2.htm (2 of 17) [30/08/2003 9:34:28 PM] . The elements array contains an entry for each radio button in a Radio object.

catalog. or not converted at all. Each text field has an onChange event handler that converts the field value depending on which radio button is checked. <HTML> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. The example also defines a text field that defaults to what was chosen via the radio buttons but that allows the user to type a nonstandard catalog name as well.htm (3 of 17) [30/08/2003 9:34:28 PM] .catalog. The radio buttons for uppercase and lowercase have onClick event handlers that convert all fields when the user clicks the radio button.catalog. NAME="musicChoice.value = 'classical'"> Classical Example 2. The onClick event handler sets the catalog name input field when the user clicks a radio button. Each radio button is given the same name. The radio buttons let the user choose whether the text fields are converted to uppercase or lowercase.htm defaultChecked Reflects the CHECKED attribute form property length name type value Specifies the form containing the Radio object Reflects the number of radio buttons in a Radio object Reflects the NAME attribute Reflects the TYPE attribute Reflects the VALUE attribute Methods The Radio object has the following methods: q q q blur click eval q q q focus toString valueOf Event handlers q q q onBlur onClick onFocus Examples Example 1." forming a group of buttons for which only one choice can be selected. The following example defines a radio button group to choose among three music catalogs. The following example contains a form with three text boxes and three radio buttons.value = 'soul-and-r&b'"> Soul and R&B <INPUT TYPE="radio" NAME="musicChoice" VALUE="jazz" onClick="musicForm.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.value = 'jazz'"> Jazz <INPUT TYPE="radio" NAME="musicChoice" VALUE="classical" onClick="musicForm. <INPUT TYPE="text" NAME="catalog" SIZE="20"> <INPUT TYPE="radio" NAME="musicChoice" VALUE="soul-and-r&b" onClick="musicForm.

form1.value.firstName.toUpperCase() document.firstName. See also Checkbox object.toLowerCase() } } </SCRIPT> <BODY> <FORM NAME="form1"> <B>Last name:</B> <INPUT TYPE="text" NAME="lastName" SIZE=20 onChange="convertField(this)"> <BR><B>First name:</B> <INPUT TYPE="text" NAME="firstName" SIZE=20 onChange="convertField(this)"> <BR><B>City:</B> <INPUT TYPE="text" NAME="cityName" SIZE=20 onChange="convertField(this)"> <P><B>Convert values to:</B> <BR><INPUT TYPE="radio" NAME="conversion" VALUE="upper" onClick="if (this.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.firstName.cityName.lastName.form1.value = document.form1.cityName.form1.form1.toLowerCase() document.checked) {convertAllFields('upper')}"> Upper case <BR><INPUT TYPE="radio" NAME="conversion" VALUE="lower" onClick="if (this.value = document. Form object.toUpperCase()} else { if (document.value.lastName.value = field.checked) {convertAllFields('lower')}"> Lower case <BR><INPUT TYPE="radio" NAME="conversion" VALUE="noChange"> No conversion </FORM> </BODY> </HTML> See also the example for the Link object.form1.value = field.cityName.form1.form1.form1.form1.value.toLowerCase()} } } function convertAllFields(caseChange) { if (caseChange=="upper") { document.toUpperCase() document.conversion[0].form1.checked) { field.value.cityName.conversion[1].value. Select object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.form1.form1.toLowerCase() document.value.firstName.lastName.value.value = document.value = document.lastName.value.form1.htm <HEAD> <TITLE>Radio object example</TITLE> </HEAD> <SCRIPT> function convertField(field) { if (document.checked) { field.value = document.toUpperCase()} else { document.value = document.htm (4 of 17) [30/08/2003 9:34:28 PM] .

random() } referrer Property. as in Java. Specifies the URL of the calling document when a user clicks a link.0: works on all platforms. Syntax document.referrer Property of document Implemented in file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. Returns a pseudo-random number between zero and one.random() Method of Math Implemented in q q Navigator 2. In previous releases.htm (5 of 17) [30/08/2003 9:34:28 PM] .htm random Method. Examples //Returns a random number between 0 and 1 function getRandom() { return Math. The random number generator is seeded from current time. it worked on Unix platforms only.0 Navigator 3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. Syntax Math.

updates related arrays such as the plugins array. or used some other means to get to the current URL. referrer is a read-only property. referrer is empty if the user typed a URL in the Location box.plugins. and reloads all open documents that contain embedded objects (<EMBED> tag). Makes newly installed plug-ins available.referrer } refresh Method. If the user clicked on a link to get to the current URL.0 Tainted? Yes Description When a user navigates to a destination document by clicking a Link object on a source document. It returns the URL of the source document. referrer contains the URL the user linked from.htm Navigator 2.htm (6 of 17) [30/08/2003 9:34:28 PM] . false refreshes the plugins array to make newly installed plug-ins available. Syntax navigator. Evaluate the referrer property from the destination document. referrer is also empty if the server does not provide environment variable information. and optionally reloads open documents that contain plug-ins.refresh([true|false]) Parameters true refreshes the plugins array to make newly installed plug-ins available. the getReferrer function is called from the destination document. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. Examples In the following example. the referrer property contains the URL of the source document. function getReferrer() { return document. but does not reload open documents.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.

Syntax location. Examples The following code refreshes arrays and reloads open documents containing embedded objects: navigator.reload([true]) Parameters true forces an unconditional HTTP GET of the document from the server.plugins. Forces a reload of the window's current document. When the user installs a plug-in.0 Description The refresh method makes newly installed plug-ins available by updating related arrays such as the plugins array.refresh(true) See also go. This should not be used unless you have reason to believe that disk and memory caches are off or broken.htm Method of plugins array Implemented in Navigator 3. Method of file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.htm (7 of 17) [30/08/2003 9:34:28 PM] . replace methods reload Method.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. refresh reloads all open documents that contain plug-ins. that plug-in is not available until refresh is called or the user closes and restarts Navigator. or the server has a new version of the document (possibly it is generated by a CGI on each request). reload. If the true keyword is specified.

In event handlers.gif')">Killer whale <BR><INPUT TYPE="radio" NAME="imageChoice" VALUE="image3" onClick="displayImage('humpback.images[0]. Clicking another button lets the user reload the document. or Never). unless the user has set the preference to Every Time. unless the user has specified Every Time and the document has changed on the server since it was last loaded and saved in the cache. in which case it does a "conditional GET" request using an If-modified-since HTTP header.src=theImage } </SCRIPT> <FORM NAME="imageForm"> <B>Choose an image:</B> <BR><INPUT TYPE="radio" NAME="imageChoice" VALUE="image1" CHECKED onClick="displayImage('seaotter. which is a synonym for document.location. reload will reload from the cache. This method uses the same policy that the Navigator's Reload button uses (Once per Session.URL. Examples The following example displays an image and three radio buttons. <SCRIPT> function displayImage(theImage) { document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.location.htm location Implemented in Navigator 3. The user can click the radio buttons to choose which image is displayed.reload() instead of simply using location. to ask the server to return the document only if its last-modified time is newer than the time the client keeps in its cache.location.gif')">Humpback whale <BR> <IMG NAME="marineMammal" SRC="seaotter.gif')">Sea otter <BR><INPUT TYPE="radio" NAME="imageChoice" VALUE="image2" onClick="displayImage('orca.0 Description The reload method forces a reload of the document specified by the URL in the location. a call to location without specifying an object name is equivalent to document. The user sets the default value of this policy by choosing Network Preferences from the Options menu and specifying Verify Documents on the Cache tab of the Preferences dialog box. you must specify window. Due to the scoping of static objects in JavaScript.reload().htm (8 of 17) [30/08/2003 9:34:28 PM] .reload()"> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. Every Time. In other words.href property. The reload method does not force a transaction with the server.gif" ALIGN="left" VSPACE="10"> <P><INPUT TYPE="button" VALUE="Click here to reload" onClick="window.

which is a synonym for document. This emulates replace.URL. a call to location without specifying an object name is equivalent to document. Method of location Implemented in Navigator 3.replace = location.htm (9 of 17) [30/08/2003 9:34:28 PM] .0 Description The replace method loads the specified URL over the current history entry.replace("URL") Parameters URL specifies the URL to load.replace == null) location. Syntax location.location. so after the replace method is used. you could put the following line in a <SCRIPT> tag early in your program.assign file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. which was introduced in Navigator 3. If your program will be run with JavaScript in Navigator 2. Loads the specified URL over the current history entry. refresh.htm </FORM> See also go.location. the user cannot navigate to the previous URL by using Navigator's Back button.0. Due to the scoping of static objects in JavaScript. In event handlers.replace() instead of simply using location.0: if (location. you must specify window. replace methods replace Method.replace().file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.

reload methods file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.catalogForm.season. Examples The following example lets the user choose among several catalogs to display. replacing the current URL with the URL appropriate for the catalog the user has chosen. for example the Spring/Summer Clothing catalog or the Fall/Winter Home & Garden catalog.value i=document. i++) { if (document.length. When the user clicks the Go button. "replace" parameter of open (document object) method.checked) { catName=document.checked) { seaName=document. go.catalogForm.catalogForm.season[i].season. Note that after the replace method is used. <SCRIPT> function displayCatalog() { var seaName="" var catName="" for (var i=0. The example displays two sets of radio buttons which let the user choose a season and a category. use go. refresh. the user cannot navigate to the previous URL (the list of catalogs) by using Navigator's Back button.category) { if (document.value i=document.htm (10 of 17) [30/08/2003 9:34:28 PM] .catalogForm. the displayCatalog function executes the replace method.catalogForm.catalogForm.category.season[i].category[i]. i < document.category[i].catalogForm.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.replace(fileName) } </SCRIPT> <FORM NAME="catalogForm"> <B>Which catalog do you want to see?</B> <P><B>Season</B> <BR><INPUT TYPE="radio" NAME="season" VALUE="q1" CHECKED>Spring/Summer <BR><INPUT TYPE="radio" NAME="season" VALUE="q3">Fall/Winter <P><B>Category</B> <BR><INPUT TYPE="radio" NAME="category" VALUE="clo" CHECKED>Clothing <BR><INPUT TYPE="radio" NAME="category" VALUE="lin">Linens <BR><INPUT TYPE="radio" NAME="category" VALUE="hom">Home & Garden <P><INPUT TYPE="button" VALUE="Go" onClick="displayCatalog()"> </FORM> See also history object.html" location.length } } for (var i in document.length } } fileName=seaName + catName + ".htm The replace method does not create a new entry in the history list. To create an entry in the history list while loading a URL.catalogForm.

defaults are restored and the form's onReset event handler displays a message. <SCRIPT> function verifyInput(textObject) { if (textObject. Examples The following example displays a Text object in which the user is to type "CA" or "AZ".reset() Parameters formName is the name of any form or an element in the forms array.htm (11 of 17) [30/08/2003 9:34:28 PM] .0 Description The reset method restores a form element's default values.')"> Enter CA or AZ: <INPUT TYPE="text" NAME="state" SIZE="2" onChange=verifyInput(this)><P> </FORM> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.htm reset method Method.reset() } } </SCRIPT> <FORM NAME="form1" onReset="alert('Please enter CA or AZ.value == 'CA' || textObject. Method of Form object Implemented in Navigator 3. Simulates a mouse click on a reset button for the calling form. A reset button does not need to be defined for the form.value == 'AZ') { alert('Nice input') } else { document. The Text object's onChange event handler calls a function that executes the form's reset method if the user provides incorrect input. When the reset method executes.form1. Syntax formName.

elements[index]. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.htm See also onReset event handler.methodName(parameters) formName. HTML syntax To define a reset button. Reset object Reset object Object.propertyName formName.propertyName resetName. A reset button resets all elements in a form to their defaults. VALUE="buttonText" specifies the text to display on the button face. 4. resetName.elements[index].methodName(parameters) Parameters resetName is the value of the NAME attribute of a Reset object. 2. 3. Syntax To use a Reset object's properties and methods: 1.htm (12 of 17) [30/08/2003 9:34:28 PM] . use standard HTML syntax with the addition of JavaScript event handlers: <INPUT TYPE="reset" NAME="resetName" VALUE="buttonText" [onBlur="handlerText"] [onClick="handlerText"] [onFocus="handlerText"]> HTML attributes NAME="resetName" specifies the name of the Reset object. A reset button on an HTML form. and you can use this name when indexing the elements array. You can access this value using the value property.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. You can access this value using the name property.

propertyName is one of the properties listed below. methodName is one of the methods listed below. index is an integer representing a Reset object on a form or the name of a Reset object as specified by the NAME attribute. added onBlur and onFocus event handlers. Property of Form object Implemented in q q Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.htm formName is either the value of the NAME attribute of a Form object or an element in the forms array. once the button is clicked.htm (13 of 17) [30/08/2003 9:34:28 PM] . the reset cannot be canceled. Properties The Reset object has the following properties: Property name type value Description Reflects the NAME attribute Reflects the TYPE attribute Reflects the VALUE attribute form property Specifies the form containing the Reset object Methods The Reset object has the following methods: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.0: added type property. added blur and focus methods Description A Reset object on a form looks as follows: Defaults A Reset object is a form element and must be defined within a <FORM> tag.0 Navigator 3. The reset button's onClick event handler cannot prevent a form from being reset.

The following example displays a Text object with the default value "CA" and a reset button with the text "Clear Form" displayed on its face.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. <HTML> <HEAD> <TITLE>Reset object example</TITLE> </HEAD> <BODY> <FORM NAME="form1"> <BR><B>City: </B><INPUT TYPE="text" NAME="city" VALUE="Santa Cruz" SIZE="20"> <B>State: </B><INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2"> <P><SELECT NAME="colorChoice"> <OPTION SELECTED> Blue <OPTION> Yellow <OPTION> Green <OPTION> Red </SELECT> <P><INPUT TYPE="radio" NAME="musicChoice" VALUE="soul-and-r&b" CHECKED> Soul and R&B <BR><INPUT TYPE="radio" NAME="musicChoice" VALUE="jazz"> Jazz <BR><INPUT TYPE="radio" NAME="musicChoice" VALUE="classical"> Classical <P><INPUT TYPE="reset" VALUE="Defaults" NAME="reset1"> </FORM> </BODY> </HTML> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. a Select object. The following example displays two Text objects. <B>State: </B><INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2"> <P><INPUT TYPE="reset" VALUE="Clear Form"> Example 2.htm (14 of 17) [30/08/2003 9:34:28 PM] . and three radio buttons. the original values are restored. all of these objects have default values. The form also has a reset button with the text "Defaults" on its face. If the user changes the value of any of the objects and then clicks the Defaults button. If the user types a state abbreviation in the Text object and then clicks the Clear Form button.htm q q q blur click eval q q q focus toString valueOf Event handlers q q q onBlur onClick onFocus Examples Example 1. the original value of "CA" is restored.

Submit object reverse Method. "three") myArray. myArray = new Array("one". Examples The following example creates an array myArray. Transposes the elements of an array: the first array element becomes the last and the last becomes the first.reverse() Parameters arrayName is the name of an Array object or a property of an existing object.reverse() This code changes myArray so that: q q q myArray[0] is "three" myArray[1] is "two" myArray[2] is "one" file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. containing three elements. onReset event handler. reset method.htm See also Button object. Form object.htm (15 of 17) [30/08/2003 9:34:28 PM] . Syntax arrayName.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r. Method of Array Implemented in Navigator 3. "two". then reverses the array.0 Description The reverse method transposes the elements of the calling array object.

htm (16 of 17) [30/08/2003 9:34:28 PM] .49)) is " + Math.round(number) Parameters number is any numeric expression or a property of an existing object.5 or greater.round(20. Examples //Displays the value 20 document. Returns the value of a number rounded to the nearest integer. the argument is rounded to the next lowest integer.round(20. Syntax Math.write("<P>The rounded value //Displays the value -20 document.51)) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.5. sort methods round Method.write("<P>The rounded value " + Math.write("The rounded value is //Displays the value 21 document. Method of Math Implemented in Navigator 2.0 Description If the fractional portion of number is .round(-20. If the fractional portion of number is less than .round(-20.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.write("<P>The rounded value //Displays the value -21 document.htm See also join. the argument is rounded to the next highest integer.5)) is " + Math.5)) is " + Math.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.htm [Next reference file] file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_r-r.htm (17 of 17) [30/08/2003 9:34:28 PM] .

The following code.0 Description JavaScript does not reflect document dimensions in pixels. Syntax windowReference. Scrolls a window to a specified coordinate. scrolls a second frame.htm (1 of 44) [30/08/2003 9:34:32 PM] . Method of window object Implemented in Navigator 3.x.value) var y = parseInt(form. Two Text objects let the user specify the x and y coordinates. When the user clicks the Go button. you must hardcode the x and y coordinates.0. x-coordinate is an integer representing the x-coordinate in pixels. which exists in one frame. as described in the window object.y.y-coordinate) Parameters windowReference is a valid way of referring to a window.frame2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.100) Example 2: Scroll a different window. y-coordinate is an integer representing the y-coordinate in pixels. the document in frame2 scrolls to the specified coordinates. so when using the scroll method.100. The following example scrolls the current window to the coordinates 50.scroll(x-coordinate. <SCRIPT> function scrollIt(form) { var x = parseInt(form.scroll(50. Examples Example 1: Scroll the current window.value) parent. window. A document's upper left coordinates are 0.scroll(x. y) } </SCRIPT> <BODY> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.htm [Previous reference file] scroll Method.

search Parameters index is an integer representing a Link object or the name of a Link object as specified by the NAME attribute. links[index]. each pair is separated by an ampersand. Link object.myForm)"> </FORM> search Property. location. A string beginning with a question mark that specifies any query information in the URL.search 3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. Property of Area object (see Link object). This property applies to http URLs only. For example.htm (2 of 44) [30/08/2003 9:34:32 PM] . areaName is the value of the NAME attribute of an Area object. Syntax 1.htm <FORM NAME="myForm"> <P><B>Specify the coordinates to scroll to:</B> <BR>Horizontal: <INPUT TYPE="text" NAME=x VALUE="0" SIZE=4> <BR>Vertical: <INPUT TYPE="text" NAME=y VALUE="0" SIZE=4> <BR><INPUT TYPE="button" VALUE="Go" onClick="scrollIt(document. areaName.0: property of Area Tainted? Yes Description The search property specifies a portion of the URL. location object Implemented in q q Navigator 2.search 2. The search property contains variable and value pairs.0 Navigator 3. two pairs in a search string could look like the following: ?x=7&y=5 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.

location.search + "<P>") msgWindow.hostName = guide-p.write("newWindow.location.search = ?qt=RFC+1738+&col=WW See also hash.protocol + "<P>") msgWindow.write("newWindow.location.hash + "<P>") msgWindow.location.location.protocol = " + newWindow. the window.location.port = " + newWindow.host = " + newWindow.host + "<P>") msgWindow.location.href = http://guide-p. Due to the scoping of static objects in JavaScript.location.location.location.write("newWindow.com/WW/NS/Titles?qt=RFC+1738+&col=WW newWindow. The document.search instead of simply using location. Examples In the following example.infoseek.infoseek.location.href + "<P>") msgWindow.com newWindow.port + "<P>") msgWindow.location.location. hostname.search = " + newWindow.location.com newWindow.hash = newWindow.search. href. If the search that you specify cannot be found in the current location.document.write("newWindow. port.host = guide-p.location.location.protocol = http: newWindow. a call to location without specifying an object name is equivalent to document.document. host.port = newWindow.hostName = " + newWindow. you must specify window.document.location.location.pathname = /WW/NS/Titles newWindow.write statements display all the properties of newWindow.location in a window called msgWindow.write("newWindow.open statement creates a window called newWindow and loads the specified URL into it.open ("http://guide-p.htm (3 of 44) [30/08/2003 9:34:32 PM] .infoseek.hostName + "<P>") msgWindow. you will get an error.location.pathname = " + newWindow.URL. protocol properties file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.location.write("newWindow.infoseek.location. which is a synonym for document.htm You can set the search property at any time.pathname + "<P>") msgWindow.document. In event handlers.close() The previous example displays the following output: newWindow. newWindow=window.location.href = " + newWindow.location.location. pathname.document.document.document.location.document.3 of RFC 1738 for complete information about the search. although it is safer to set the href property to change a location.write("newWindow.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.location. See Section 3.hash = " + newWindow.com/WW/NS/Titles?qt=RFC+1738+&col=WW") msgWindow.document.write("newWindow.

Method of Password object. Text object. or Textarea object.select() Parameters passwordName is either the value of the NAME attribute of a Password object or an element in the elements array. Textarea object Implemented in Navigator 2. the select method highlights the password field and the focus method returns focus to it so the user can re-enter the password. the checkPassword function confirms that a user has entered a valid password.select() } } This example assumes that the password is defined as <INPUT TYPE="password" NAME="userPass"> See also file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.htm (4 of 44) [30/08/2003 9:34:32 PM] .0 Description Use the select method to highlight the input area of a form element. textName is either the value of the NAME attribute of a Text object or an element in the elements array.") userPass. function checkPassword(userPass) { if (badPassword) { alert("Please enter your password again. Selects the input area of the specified Password. textName. Text. You can use the select method with the focus method to highlight a field and position the cursor for a user response.focus() userPass. textareaName is either the value of the NAME attribute of a Textarea object or an element in the elements array. Examples In the following example.select() 2. passwordName.htm select method Method.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.select() 3. textareaName. If the password is not valid. Syntax 1.

. SELECTED specifies that the option is selected by default. textToDisplay specifies the text to display in the list. You can access this value using the text property. OPTION specifies a selection element in the list. SIZE="integer" specifies the number of options visible when the form is displayed. Syntax To create an option to add to an existing Select object: optionName = new Option([text. If omitted. use standard HTML syntax with the addition of JavaScript event handlers: <SELECT NAME="selectName" [SIZE="integer"] [MULTIPLE] [onBlur="handlerText"] [onChange="handlerText"] [onFocus="handlerText"]> <OPTION VALUE="optionValue" [SELECTED]> textToDisplay [ .options[index1]=optionName file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. VALUE="optionValue" specifies a value that is returned to the server when the option is selected and the form is submitted. You can access this value using the defaultSelected property. MULTIPLE specifies that multiple items can be selected. defaultSelected. value. You can access this value using the value property.htm (5 of 44) [30/08/2003 9:34:32 PM] . focus methods Select object Object. only one item can be selected from the list. <OPTION> textToDisplay] </SELECT> HTML attributes NAME="selectName" specifies the name of the Select object. A selection list on an HTML form. You can access the options using the options array. HTML syntax To define a Select object.htm blur. You can access this value using the name property. selected]) To add the new option to an existing Select object: selectName.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.. and you can use this name when indexing the elements array. The user can choose one or more items from a selection list.

options[index1].file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.options[index1]. selected specifies the current selection state of the option (true or false).htm (6 of 44) [30/08/2003 9:34:32 PM] .propertyName 3. You can access this value using the selected property. selectName. optionName. selectName is the value of the NAME attribute of a Select object.methodName(parameters) To use an option's properties: 1. index is an integer representing a Select object on a form or the name of a Select object as specified by the NAME attribute.elements[index2].elements[index]. You can access this value using the defaultSelected property.options[index1] = null To use a Select object's properties and methods: 1. 4. formName is either the value of the NAME attribute of a Form object or an element in the forms array. When using Option properties and methods. You can access this value using the text property.htm To delete an option from a Select object: selectName. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. The options array is a property of the Select object. optionName is either the name of an existing Option object or a property of an existing object. defaultSelected specifies whether the option is initially selected (true or false). 2.propertyName formName. You can access this value using the value property. methodName is one of the methods listed below. selectName. text specifies the text to display in the select list. index1 is an integer representing an option in a Select object. Property of q q The Select object is a property of the Form object. index2 is an integer representing a Select object on a form. formName. propertyName is one of the properties listed below.propertyName 2.methodName(parameters) formName.elements[index].propertyName selectName. 3. value specifies a value that is returned to the server when the option is selected and the form is submitted.propertyName Parameters optionName is either the name of a new object or a property of an existing object.

added type property. selectName.options. you have to loop and test each option individually: for (var i = 0.htm Implemented in q q Navigator 2. Elements in the options array are read-only.options[1].file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.options 2. The options array You can reference the options of a Select object in your code by using the options array. selectName. and musicStyle. For Select objects that can have multiple selections (the <SELECT> tag has the MULTIPLE attribute).options[0]="guitar" has no effect. musicStyle.0 Navigator 3. use the length property of either the options array or the Select object: 1. index is an integer representing an option in a Select object. Each element in the options array represents a Select option.htm (7 of 44) [30/08/2003 9:34:32 PM] .length 2. the user can choose multiple items from the list on the right: R&B Jazz Blues New Age R&B A Select object is a form element and must be defined within a <FORM> tag. To use the options array: 1.options. selectName. selectName.options represents the full HTML statement for the selectName object. The user can choose one item from the list on the left. if a Select object named musicStyle contains three options.options[2].length. added the ability to add and delete options Description A Select object on a form looks as follows. For example. i++) { if (select. the value returned by selectName.options.options[index] 3. To obtain the number of options in a Select object.0: text property can be changed to change the text of an option. these options are reflected as musicStyle.options[i]. selectName.length The Select object has properties that you can access only through the options array.options[0]. This array contains an entry for each option in a Select object (<OPTION> tag) in source order.length selectName is either the value of the NAME attribute of a Select object or an element in the elements array. i < select. For example. These properties are listed below. the statement selectName.selected) // Statements to perform if option is selected file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. added Option() constructor and all its properties.

options[i].text = theForm. q The selectedIndex property for a Select object is an integer specifying the index of the selected option.htm (8 of 44) [30/08/2003 9:34:32 PM] .selected = true } </SCRIPT> <FORM> <SELECT name="userChoice"> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.userChoice.myForm. The following statement sets an option's selected property to true: document.options[i]. For example.selected = true q Changing option text To change an option's text. or 2): Change Selection The code for this example looks as follows: <SCRIPT> function updateList(theForm.musicTypes. 1.options[i]. Choice 1 New text for the option: Option to change (0.whatsNew. otherwise it is false. This is more useful for Select objects that are created with the MULTIPLE attribute. suppose a form has the following Select object: <SELECT name="userChoice"> <OPTION>Choice 1 <OPTION>Choice 2 <OPTION>Choice 3 </SELECT> You can set the text of the ith item in the selection based on text entered in a text field named whatsNew as follows: myform.selectedIndex = i The selected property for an option is a Boolean value specifying the current selection state of the option in a Select object. the user can enter some text in the first text field and then enter a number between 0 and 2 (inclusive) in the second text field.whatsNew.userChoice. } Changing the selection state You can use the selected and selectedIndex properties to change the selection state of options in a Select object.htm .musicTypes. use the text property of the options array. The following statement sets a Select object's selectedIndex property: document.userChoice.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.myForm. the text will be substituted for the indicated option number and that option is selected. If an option is selected. For example. its selected property is true. in the following form... i) { theForm.value theForm.options[i].value You do not need to reload or refresh after changing an option's text.text = myform. This is most useful for Select objects that are created without the MULTIPLE attribute. When the user clicks the button.

form. Properties The Select object has the following properties: Property Description form property Specifies the form containing the Select object length name options Reflects the number of options in a Select object Reflects the NAME attribute Reflects the <OPTION> tags selectedIndex Reflects the index of the selected option (or the first selected option. if you delete options[0]. Deleting options Deletion compresses the options array. After you create the options and add them to the Select object. This statement must be last. When the document reloads. the existing options[1] becomes options[0].go(0).htm (9 of 44) [30/08/2003 9:34:32 PM] . you must refresh the document by using history. variables are lost if not saved in cookies or form element values.idx. 1. or 2): <INPUT TYPE="text" NAME="idx"> <BR> <INPUT TYPE="button" VALUE="Change Selection" onClick="updateList(this. This statement must be last.value)"> </FORM> Adding options using the Option() constructor Each option created using the Option() constructor is an object and has the same properties as elements of the options array.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. this. if multiple options are selected) type Specifies that the object is a Select object and indicates whether MULTIPLE is specified The options array has the following properties: Property length Description Reflects the number of options in a Select object selectedIndex Reflects the index of the selected option Each element of the options array has the following properties: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. For example.form. you must refresh the document by using history.go(0). variables are lost if not saved in cookies or form element values. After you delete an option. It's a good idea to delete options at the end of the array first. When the document reloads.htm <OPTION>Choice 1 <OPTION>Choice 2 <OPTION>Choice 3 </SELECT> <BR> New text for the option: <INPUT TYPE="text" NAME="whatsNew"> <BR> Option to change (0.

htm Property Description defaultSelected Reflects the SELECTED attribute index selected text property value Reflects the index of an option Lets you programmatically select an option Reflects the textToDisplay that follows an <OPTION> tag Reflects the VALUE attribute Objects created with the Option() constructor have the following properties: Property Description defaultSelected Specifies the initial selection state of the option index prototype selected text property value Specifies the index of the option in a Select object Lets you add a properties to an option. The following example displays two selection lists. Specifies the current selection state of the option Specifies the text for the option Specifies the value that is returned to the server when the option is selected and the form is submitted Methods The Select object has the following methods: q q q blur eval focus q q toString valueOf Event handlers q q q onBlur onChange onFocus Examples Example 1. Choose the music type for your free CD: <SELECT NAME="music_type_single"> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT> <P>Choose the music types for your free CDs: <BR><SELECT NAME="music_type_multi" MULTIPLE> <OPTION SELECTED> R&B <OPTION> Jazz file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. the user can select only one item. In the first list.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. the user can select multiple items.htm (10 of 44) [30/08/2003 9:34:32 PM] . in the second list.

The user can change the month and day by using the selection lists or by choosing preset dates from radio buttons.options[monthInteger].value="Yes!" else document.document.options[4].value=monthObj.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.length document.selectForm.textCinco.textCinco.selectForm.selectForm.textMonthLength.value=monthObj. <HTML> <HEAD> <TITLE>Select object example</TITLE> </HEAD> <BODY> <SCRIPT> var today = new Date() //--------------function updatePropertyDisplay(monthObj.selected && dayObj. monthString.htm (11 of 44) [30/08/2003 9:34:32 PM] .textDayName.selectedIndex dayInteger=dayObj.textMonthName.selectForm.textMonthIndex. dayInteger.selectForm. Text fields on the form display the values of the Select object's properties and indicate the date chosen and whether it is Cinco de Mayo.selectForm.selectedIndex // Is it Cinco de Mayo? if (monthObj.daySelection)"> <OPTION> January <OPTION> February <OPTION> March <OPTION> April <OPTION> May <OPTION> June <OPTION> July <OPTION> August <OPTION> September <OPTION> October <OPTION> November <OPTION> December </SELECT> Day: <SELECT NAME="daySelection" onChange="updatePropertyDisplay(document.selectForm. The following example displays two selection lists that let the user choose a month and day.selectForm. dayString monthInteger=monthObj.text dayString=dayObj.length document.value="No" } </SCRIPT> <!---------------> <FORM NAME="selectForm"> <P><B>Choose a month and day:</B> Month: <SELECT NAME="monthSelection" onChange="updatePropertyDisplay(this.selectedIndex document.value=dayObj.textDayIndex.options[dayInteger].monthSelection.textFullDate.name document.selectedIndex monthString=monthObj.htm <OPTION> Blues <OPTION> New Age </SELECT> Example 2.text // Display property values document.value=monthString + " " + dayString document.this)"> <OPTION> 1 <OPTION> 2 <OPTION> 3 <OPTION> 4 <OPTION> 5 <OPTION> 6 <OPTION> 7 <OPTION> 8 <OPTION> 9 <OPTION> 10 <OPTION> 11 <OPTION> 12 <OPTION> 13 <OPTION> 14 <OPTION> 15 <OPTION> 16 <OPTION> 17 <OPTION> 18 <OPTION> 19 <OPTION> 20 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.dayObj) { // Get date strings var monthInteger.selectForm.selectForm.selected) document.textDayLength. These selection lists are initialized to the current date.value=dayObj.value=monthObj.selectForm.value=dayObj.name document.options[4].

getMonth() document. "Green") var option0 = new Option("Red".file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. one without the MULTIPLE attribute and one with.selectForm.document. "Yellow".selectedIndex=today.daySelection.selectedIndex <INPUT TYPE="text" NAME="textMonthIndex" VALUE="" SIZE=20"> <BR>daySelection.document.monthSelection. the populate function creates four options for the Select object and selects the first option. The following example creates two Select objects.htm (12 of 44) [30/08/2003 9:34:32 PM] . Add an option using the Option() constructor. daySelection.daySelection)"> Cinco de Mayo <INPUT TYPE="radio" NAME="dateChoice" onClick=" monthSelection.selectForm.selectedIndex=0. <SCRIPT> function populate(inForm) { colorArray = new Array("Red".daySelection) </SCRIPT> </FORM> </BODY> </HTML> Example 3. "Blue".selectedIndex=0.length<INPUT TYPE="text" NAME="textMonthLength" VALUE="" SIZE=20"> <BR>daySelection.selectedIndex<INPUT TYPE="text" NAME="textDayIndex" VALUE="" SIZE=20"> <BR>Is it Cinco de Mayo? <INPUT TYPE="text" NAME="textCinco" VALUE="" SIZE=20"> <SCRIPT> document.selectedIndex=today.daySelection)"> New Year's Day <INPUT TYPE="radio" NAME="dateChoice" onClick=" monthSelection.selectForm. No options are initially defined for either object.selectForm.document. daySelection.selectForm.selectForm.selectedIndex=4. "color_red") var option1 = new Option("Blue".selectedIndex=5.monthSelection. updatePropertyDisplay document.length<INPUT TYPE="text" NAME="textDayLength" VALUE="" SIZE=20"> <BR>monthSelection.name<INPUT TYPE="text" NAME="textDayName" VALUE="" SIZE=20"> <BR>monthSelection.monthSelection. updatePropertyDisplay (document.name<INPUT TYPE="text" NAME="textMonthName" VALUE="" SIZE=20"> <BR>daySelection.htm <OPTION> 21 <OPTION> 22 <OPTION> 23 <OPTION> 24 <OPTION> 25 <OPTION> 26 <OPTION> 27 <OPTION> 28 <OPTION> 29 <OPTION> 30 <OPTION> 31 </SELECT> <P><B>Set the date to: </B> <INPUT TYPE="radio" NAME="dateChoice" onClick=" monthSelection.selectedIndex=4.monthSelection. "color_blue") file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. When the user clicks a button associated with the Select object.selectForm.selectForm.selectForm.daySelection)"> Summer Solstice <P><B>Property values:</B> <BR>Date chosen: <INPUT TYPE="text" NAME="textFullDate" VALUE="" SIZE=20"> <BR>monthSelection.selectForm.document. updatePropertyDisplay (document.monthSelection.getDate()-1 updatePropertyDisplay(document.selectedIndex=20. daySelection.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. Syntax 1.options[i]=option" + i) if (i==0) { inForm. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.form)"> <P> </FORM> <HR> <H3>Select-Multiple Option() constructor</H3> <FORM> <SELECT NAME="selectTest" multiple></SELECT><P> <INPUT TYPE="button" VALUE="Populate Select List" onClick="populate(this. A Boolean value indicating whether an option in a Select object is selected. "color_green") for (var i=0.options[itemNo]=null history. function deleteAnItem(theList.itemNo) { theList.htm var option2 = new Option("Yellow".go(0) } </SCRIPT> <H3>Select Option() constructor</H3> <FORM> <SELECT NAME="selectTest"></SELECT><P> <INPUT TYPE="button" VALUE="Populate Select List" onClick="populate(this. Radio object selected Property.htm (13 of 44) [30/08/2003 9:34:32 PM] .selected=true } } history. See also Form object. i < 4.selectTest. Delete an option. "color_yellow") var option3 = new Option("Green". The following function removes an option from a Select object.options[index]. selectName.selected Parameters selectName is either the value of the NAME attribute of a Select object or an element in the elements array. i++) { eval("inForm. optionName.form)"> </FORM> Example 4.go(0) } See also the examples for the defaultSelected property.options[i].selected 2.selectTest.

Examples See the examples for the defaultSelected property.selectedIndex 2.htm (14 of 44) [30/08/2003 9:34:32 PM] . index. optionName is the name of a Select object option created using the Option() constructor.selectedIndex Parameters file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.htm index is an integer representing an option in a Select object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. otherwise. and you can select individual options without clearing the selection of other options. With the selected property. The display of the Select object updates immediately when you set the selected property. An integer specifying the index of the selected option in a Select object. Syntax 1. it is false. You can set the selected property at any time.0 Navigator 3. selectedIndex properties selectedIndex Property. selectName. you can evaluate every option in the options array to determine multiple selections.options. See also defaultSelected. In general.0: property of Option Tainted? Yes Description If an option in a Select object is selected. Property of Option object (see Select object). the selected property is more useful than the selectedIndex property for Select objects that are created with the MULTIPLE attribute. the value of its selected property is true. options array (see Select object) Implemented in q q Navigator 2. selectName.

If no option is selected.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. The display of the Select object updates immediately when you set the selectedIndex property.selectedIndex } The previous example assumes that the Select object is similar to the following: <SELECT NAME="musicType"> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT> See also defaultSelected. the getSelectedIndex function returns the selected index in the musicType Select object: function getSelectedIndex() { return document. You can set the selectedIndex property at any time. Property of Select object. starting with an index of zero.htm (15 of 44) [30/08/2003 9:34:32 PM] . the selectedIndex property is more useful for Select objects that are created without the MULTIPLE attribute. selected properties file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.musicForm.0 Tainted? Yes Description Options in a Select object are indexed in the order in which they are defined. options array (see Select object) Implemented in Navigator 2. selectedIndex has a value of -1.musicType. In general. Both forms of the syntax specify the same value. The selected property of the Select object's options array is more useful for Select objects that are created with the MULTIPLE attribute. With the selected property. Examples In the following example. Setting selectedIndex clears any other options that are selected in the Select object.htm selectName is either the value of the NAME attribute of a Select object or an element in the elements array. the selectedIndex property specifies the index of the first option only. and you can select individual options without clearing the selection of other options. If you evaluate selectedIndex when multiple options are selected. index. you can evaluate every option in the options array to determine multiple selections.

href=pickRandomURL()" file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. window object Implemented in Navigator 2. or name property when self refers to a window object. You can also use the self property to make your code more readable. The value of the self property is <object nameAttribute> where nameAttribute is the NAME attribute if self refers to a frame. status. or an internal reference if self refers to a window. self. Examples In the following example. self. Property of Frame object. self. Use the self property to disambiguate a window property from a form or form element of the same name.0 Tainted? No Description The self property refers to the current window or frame. length. This usage disambiguates the status property of the current window from a form or form element called "status" within the current window.status is used to set the status property of the current window. methodName is any method associated with the window object.propertyName 2. Syntax 1. <A HREF="" onClick="this. The self property is read-only.htm self Property.methodName Parameters propertyName is the defaultStatus.htm (16 of 44) [30/08/2003 9:34:32 PM] . propertyName is the length or name property when self refers to a Frame object. The self property is a synonym for the current window or frame.

0 Examples The second statement below changes the day for theBigDay to July 24 from its original value. Syntax dateObjectName. dayValue is an integer from one to 31 or a property of an existing object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.setDate(dayValue) Parameters dateObjectName is either the name of a Date object or a property of an existing object. 1962 23:30:00") theBigDay. return true"> Go!</A> See also window property setDate Method.setDate(24) See also getDate method setHours Method.status='Pick a random URL' . file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. Sets the hours for a specified date. representing the day of the month. Method of Date Implemented in Navigator 2. Sets the day of the month for a specified date.htm onMouseOver="self. theBigDay = new Date("July 27.htm (17 of 44) [30/08/2003 9:34:32 PM] .

setMinutes(minutesValue) Parameters dateObjectName is either the name of a Date object or a property of an existing object. Method of Date Implemented in Navigator 2. hoursValue is an integer between zero and 23 or a property of an existing object. Method of Date Implemented in file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.htm Syntax dateObjectName.setHours(7) See also getHours method setMinutes Method.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.htm (18 of 44) [30/08/2003 9:34:32 PM] . representing the hour. minutesValue is an integer between zero and 59 or a property of an existing object. Syntax dateObjectName. Sets the minutes for a specified date. representing the minutes.0 Examples theBigDay.setHours(hoursValue) Parameters dateObjectName is either the name of a Date object or a property of an existing object.

0 Examples theBigDay.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.setMonth(6) See also getMonth method setSeconds file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.0 Examples theBigDay.htm Navigator 2. Syntax dateObjectName. Method of Date Implemented in Navigator 2.setMinutes(45) See also getMinutes method setMonth Method. Sets the month for a specified date. monthValue is an integer between zero and 11 (representing the months January through December) or a property of an existing object.htm (19 of 44) [30/08/2003 9:34:32 PM] .setMonth(monthValue) Parameters dateObjectName is either the name of a Date object or a property of an existing object.

representing the number of milliseconds since the epoch (1 January 1970 00:00:00). Method of Date Implemented in Navigator 2. Sets the value of a Date object. timevalue is an integer or a property of an existing object.setTime(timevalue) Parameters dateObjectName is either the name of a Date object or a property of an existing object. secondsValue is an integer between zero and 59 or a property of an existing object. Syntax dateObjectName.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.0 Examples theBigDay. Method of Date file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.setSeconds(30) See also getSeconds method setTime Method. Syntax dateObjectName. Sets the seconds for a specified date.htm (20 of 44) [30/08/2003 9:34:32 PM] .setSeconds(secondsValue) Parameters dateObjectName is either the name of a Date object or a property of an existing object.htm Method.

msec is a numeric value. if a setTimeout method specifies five seconds. It does not evaluate the expression repeatedly. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. Syntax timeoutID=setTimeout(expression. expression is a string expression or a property of an existing object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. the expression is evaluated after five seconds. Evaluates an expression after a specified number of milliseconds has elapsed.htm (21 of 44) [30/08/2003 9:34:32 PM] .setTime(theBigDay. msec) Parameters timeoutID is an identifier that is used only to cancel the evaluation with the clearTimeout method.getTime()) See also getTime method setTimeout Method. 1999") sameAsBigDay = new Date() sameAsBigDay. numeric string. Examples theBigDay = new Date("July 1.0 Description The setTimeout method evaluates an expression after a specified amount of time. not every five seconds. Method of Frame object. or a property of an existing object in millisecond units.0 Description Use the setTime method to help assign a date and time to another Date object.htm Implemented in Navigator 2. For example. window object Implemented in Navigator 2.

which is called recursively. <SCRIPT LANGUAGE="JavaScript"> function displayAlert() { alert("5 seconds have elapsed since the button was clicked.getHours() var minutes = now. the timeout is canceled and the alert does not display.htm Examples Example 1." : " A. uses the setTimeout method to update the time every second. click the button on the right to cancel the reminder before it is displayed. The following example displays the current time in a Text object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. The showtime function.value = timeValue file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.htm (22 of 44) [30/08/2003 9:34:32 PM] . <P> <INPUT TYPE="button" VALUE="5-second reminder" NAME="remind_button" onClick="timerID=setTimeout('displayAlert()'. If the user clicks the second button before the alert message is displayed.") } </SCRIPT> <BODY> <FORM> Click the button on the left for a reminder in 5 seconds.5000)"> <INPUT TYPE="button" VALUE="Clear the 5-second reminder" NAME="remind_disable_button" onClick="clearTimeout(timerID)"> </FORM> </BODY> Example 2.M.getMinutes() var seconds = now.face.M.000 milliseconds) after the user clicks a button." document.12 : hours) timeValue += ((minutes < 10) ? ":0" : ":") + minutes timeValue += ((seconds < 10) ? ":0" : ":") + seconds timeValue += (hours >= 12) ? " P. <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-var timerID = null var timerRunning = false function stopclock(){ if(timerRunning) clearTimeout(timerID) timerRunning = false } function startclock(){ // Make sure the clock is stopped stopclock() showtime() } function showtime(){ var now = new Date() var hours = now.clock. The following example displays an alert message five seconds (5.getSeconds() var timeValue = "" + ((hours > 12) ? hours .

Sets the year for a specified date.htm timerID = setTimeout("showtime()". Syntax dateObjectName.0 Examples theBigDay. Method of Date Implemented in Navigator 2.htm (23 of 44) [30/08/2003 9:34:32 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.1000) timerRunning = true } //--> </SCRIPT> </HEAD> <BODY onLoad="startclock()"> <FORM NAME="clock" onSubmit="0"> <INPUT TYPE="text" NAME="face" SIZE=12 VALUE =""> </FORM> </BODY> See also clearTimeout method setYear Method. yearValue is an integer greater than 1900 or a property of an existing object.setYear(yearValue) Parameters dateObjectName is either the name of a Date object or a property of an existing object.setYear(96) See also getYear method file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.

representing the size of an angle in radians. asin. atan. tan methods small Method. cos. Syntax stringName.PI/2. atan2. it returns 1. Causes a string to be displayed in a small font.small() file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.0 Description The sin method returns a numeric value between -1 and one.htm (24 of 44) [30/08/2003 9:34:32 PM] . Syntax Math. Examples The following function returns the sine of the variable x: function getSine(x) { return Math. Returns the sine of a number.htm sin Method.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.sin(number) Parameters number is a numeric expression or a property of an existing object. Method of Math Implemented in Navigator 2. which represents the sine of the argument. See also acos. as if it were in a <SMALL> tag.sin(x) } If you pass getSine the value Math.

Syntax arrayName. Sorts the elements of an array.big()) document. world</BIG> <P><FONTSIZE=7>Hello. Method of String Implemented in Navigator 2.write(worldString. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.htm Parameters stringName is any string or a property of an existing object. world" document.fontsize(7)) The previous example produces the same output as the following HTML: <SMALL>Hello. Examples The following example uses string methods to change the size of a string: var worldString="Hello. world</SMALL> <P><BIG>Hello.write("<P>" + worldString.sort(compareFunction) Parameters arrayName is the name of an Array object or a property of an existing object.small()) document.htm (25 of 44) [30/08/2003 9:34:32 PM] . world</FONTSIZE> See also big. fontsize methods sort Method.write("<P>" + worldString.0 Description Use the small method with the write or writeln methods to format and display a string in a document.

leave a and b unchanged with respect to each other.htm (26 of 44) [30/08/2003 9:34:32 PM] . If omitted. but if you are comparing numbers 9 needs to come before 80." not numerical) order. the sort method does not work. If a's index was less than b's before sorting. b) is greater than zero. no matter how a and b move due to sorting. Examples file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.b } JavaScript uses a stable sort: the index partial order of a and b does not change if a and b are equal.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. For example. then: q q q If compareFunction(a. If compareFunction is supplied. sort b to a lower index than a. b) { return a . the compare function can simply subtract b from a: function compareNumbers(a. Please see the release notes (after starting Netscape. elements are sorted by converting them to strings and comparing strings in lexicographic ("dictionary" or "telephone book.0 Description If compareFunction is not supplied. b) { if (a is less than b by some ordering criterion) return -1 if (a is greater than b by the ordering criterion) return 1 // a must be equal to b return 0 } To compare numbers instead of strings. If compareFunction(a. Note On some platforms. If compareFunction(a. sort b to a higher index than a. Method of Array Implemented in Navigator 3.htm compareFunction specifies a function that defines the sort order. choose Release Notes from the Help menu). b) returns zero. "80" comes before "9" in lexicographic order. If a and b are two elements being compared. So the compare function has the following form: function compare(a. the array elements are sorted according to the return value of the compare function. but sorted with respect to all different elements. b) is less than zero. the array is sorted lexicographically (in dictionary order) according to the string conversion of each element. it will be after sorting.

Blue.5.write("<B>numberArray:</B> " + numberArray.write("<B>numericStringArray:</B> " + numericStringArray.sort(compareNumbers) +"<P>") document.1.write("<B>Sorted:</B> " + stringArray.sort() +"<BR>") document.write("<B>Sorted with compareNumbers:</B> " + mixedNumericArray.5.1.Humpback numberArray: 40.200 Sorted without a compare function: 1.5 Sorted with compareNumbers: 1.write("<B>Sorted with compareNumbers:</B> " + numberArray.b } document. reverse methods file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.200 numericStringArray: 80.write("<B>stringArray:</B> " + stringArray.sort() +"<BR>") document.5.40.sort(compareNumbers) +"<P>") document. a compare function.join() +"<BR>") document. then with.write("<B>Sorted with compareNumbers:</B> " + numericStringArray.80.sort() +"<BR>") document.Beluga Sorted: Beluga.40.200 Sorted without a compare function: 1.200."9"."Beluga") numericStringArray = new Array("80".80. when a compare function is used.700 mixedNumericArray: 80."700") numberArray = new Array(40.9.write("<B>Sorted without a compare function:</B> " + numberArray.700.80.write("<B>Sorted without a compare function:</B> " + numericStringArray."Humpback"."700".200. <SCRIPT> stringArray = new Array("Blue".200) mixedNumericArray = new Array("80".200.40.5.5.write("<B>Sorted without a compare function:</B> " + mixedNumericArray.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.1.Humpback.80.9.700.join() +"<BR>") document.write("<B>mixedNumericArray:</B> " + mixedNumericArray.5.sort(compareNumbers) +"<BR>") </SCRIPT> This example produces the following output.40.700 Sorted without a compare function: 700.40.40. numbers sort correctly whether they are numbers or numeric strings.200) function compareNumbers(a. stringArray: Blue.700 See also join.join() +"<BR>") document.9 Sorted with compareNumbers: 9.1.5.htm The following example creates four arrays and displays the original array.sort() +"<P>") document.9 Sorted with compareNumbers: 1. The numeric arrays are sorted without. As the output shows."9". then the sorted arrays. b) { return a .join() +"<BR>") document.9.htm (27 of 44) [30/08/2003 9:34:32 PM] .

htm split Method. i < arrayOfStrings. Method of String Implemented in Navigator 3.write (arrayOfStrings[i] + " / ") } } var tempestString="Oh brave new world that has such people in it.Jul. After splitting the string.Feb. Splits a String object into an array of strings by separating the string into substrings. function splitString (stringToSplit. The separator is treated as a string.comma) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.Apr.Mar. the number of elements in the array.length. Examples The following example defines a function that splits a string into an array of strings using the specified separator. Syntax stringName.space) splitString(tempestString) splitString(monthString. the function displays messages indicating the original string (before the split).Sep.Jun. the separator used." var monthString="Jan.Oct.write ('<BR>The separator is: "' + separator + '"') document. If separator is omitted.Aug.0 Description The split method returns the new array.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. i++) { document.split(separator) document.write ('<P>The original string is: "' + stringToSplit + '"') document. separator specifies the character to use for separating the string." splitString(tempestString.split([separator]) Parameters stringName is any string or a property of an existing object.htm (28 of 44) [30/08/2003 9:34:32 PM] .write ("<BR>The array has " + arrayOfStrings.Nov.length + " elements: ") for (var i=0.Dec" var space=" " var comma=". the array returned contains one element consisting of the entire string.separator) { arrayOfStrings = stringToSplit.May. and the individual array elements.

Returns the square root of a number. Syntax Math.Oct.Nov.Jun.0 Description If the value of number is outside the required range.Sep. Method of Math Implemented in Navigator 2.Apr.htm This example produces the following output: The original string is: "Oh brave new world that has such people in it.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.Aug." The separator is: "undefined" The array has 1 elements: Oh brave new world that has such people in it." The array has 12 elements: Jan / Feb / Mar / Apr / May / Jun / Jul / Aug / Sep / Oct / Nov / Dec / See also charAt.Dec" The separator is: ". / The original string is: "Oh brave new world that has such people in it." The separator is: " " The array has 10 elements: Oh / brave / new / world / that / has / such / people / in / it. lastIndexOf methods sqrt Method.sqrt(number) Parameters number is any non-negative numeric expression or a property of an existing object.Mar.May. indexOf.Feb. Examples The following function returns the square root of the variable x: function getRoot(x) { file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.Jul. sqrt returns zero.htm (29 of 44) [30/08/2003 9:34:32 PM] . / The original string is: "Jan.

414213562373095. if you pass it the value two.SQRT1_2 Property of Math Implemented in Navigator 2. The square root of two. LOG2E. LOG2E. approximately 0. PI. Examples The following function returns one over the square root of two: function getRoot1_2() { return Math. it returns 1.htm (30 of 44) [30/08/2003 9:34:32 PM] . The square root of one-half. approximately 1.sqrt(x) } If you pass getRoot the value nine. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.0 Tainted? No Description Because SQRT1_2 is a constant. SQRT2 properties SQRT2 Property. LN2. it returns three. one over the square root of two.htm return Math. it is a read-only property of Math. SQRT1_2 Property.414. equivalently. LN10.707.SQRT1_2 } See also E. Syntax Math.

Examples The following function returns the square root of two: function getRoot2() { return Math.SQRT2 } See also E. LN10.src Parameters imageName is either the name of an Image object or an element in the images array. LOG2E.0 Tainted? No Description Because SQRT2 is a constant. A string specifying the URL of an image to be displayed in a document. LN2.SQRT2 Property of Math Implemented in Navigator 2. Syntax imageName. PI.htm Syntax Math. SQRT1_2 properties src Property. it is a read-only property of Math.htm (31 of 44) [30/08/2003 9:34:32 PM] . Property of file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. LOG2E.

images[0]. the image seaotter. The user can click the radio buttons to choose which image is displayed. If the URL in the src property references an image that is not the same size as the image cell it is loaded into.gif'.gif is scaled to fit in the same space originally used by beluga. if you plan to alter the lowsrc property.gif" LOWSRC="f15el.gif.htm Image Implemented in Navigator 3. suppose an Image object originally displays the file beluga.gif')">AH-64 Apache <BR> <IMG NAME="aircraft" SRC="f15e. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.src=highRes } </SCRIPT> <FORM NAME="imageForm"> <B>Choose an image:</B> <BR><INPUT TYPE="radio" NAME="imageChoice" VALUE="image1" CHECKED onClick="displayImage('f15el.htm (32 of 44) [30/08/2003 9:34:32 PM] .0 Tainted? No Description The src property initially reflects the SRC attribute of the <IMG> tag.gif')">F-15 Eagle <BR><INPUT TYPE="radio" NAME="imageChoice" VALUE="image2" onClick="displayImage('f15e2l.gif')">F-15 Eagle 2 <BR><INPUT TYPE="radio" NAME="imageChoice" VALUE="image3" onClick="displayImage('ah64l.gif'.'f15e.'ah64.highRes) { document. Each image also uses the lowsrc property to display a low-resolution image.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. <SCRIPT> function displayImage(lowRes. the new image you specify is displayed in the area defined for the original image. Examples The following example displays an image and three radio buttons.gif'.gif" ALIGN="left"> If you set myImage. Setting the src property begins loading the new URL into the image area (and aborts the transfer of any image data that is already loading into the same area).'f15e2.gif.images[0]. the source image is scaled to fit.gif'.src='seaotter.gif is not the same size as beluga. you should do so before setting the src property. When you change the src property of a displayed image.gif: <IMG NAME="myImage" SRC="beluga. Therefore.lowsrc=lowRes document.gif" ALIGN="left" VSPACE="10"><BR> </FORM> See also the examples for the Image object. even if seaotter. For example. You can change the src property at any time.

status Parameters windowReference is a valid way of referring to a window. Syntax windowReference. Property of window object Implemented in Navigator 2. such as the message that appears when a mouseOver event occurs over an anchor.0 Tainted? Yes Description Do not confuse the status property with the defaultStatus property. Specifies a priority or transient message in the status bar at the bottom of the window. The defaultStatus property reflects the default message displayed in the status bar.href=pickRandomURL()" onMouseOver="self.htm (33 of 44) [30/08/2003 9:34:32 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. You can set the status property at any time.htm See also complete. You must return true if you want to set the status property in the onMouseOver event handler.status='Pick a random URL'. as described in the window object. Examples Suppose you have created a JavaScript function called pickRandomURL that lets you select a URL at random. You can use the onClick event handler of an anchor to specify a value for the HREF attribute of the anchor dynamically. and the onMouseOver event handler to specify a custom message for the window in the status property: <A HREF="" onClick="this. return true"> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. lowsrc properties status Property.

as self.status. Causes a string to be displayed as struck-out text. world</B> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. the status property of the window is assigned to the window's self property.strike()) The previous example produces the same output as the following HTML: <BLINK>Hello.blink()) document.write(worldString. As this example shows.0 Description Use the strike method with the write or writeln methods to format and display a string in a document. See also defaultStatus property strike Method.htm Go!</A> In the preceding example. Method of String Implemented in Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. Examples The following example uses string methods to change the formatting of a string: var worldString="Hello.write("<P>" + worldString.htm (34 of 44) [30/08/2003 9:34:32 PM] . world" document.write("<P>" + worldString.italics()) document.bold()) document. you must return true to set the status property in the onMouseOver event handler.write("<P>" + worldString. as if it were in a <STRIKE> tag. world</BLINK> <P><B>Hello.strike() Parameters stringName is any string or a property of an existing object. Syntax stringName.

A series of characters. you construct strings by quoting characters). you had to add an empty string to another window's string to reference it) Description file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. Property of None Implemented in q q Navigator 2. added split method. added prototype property. world</I> <P><STRIKE>Hello. bold.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. Syntax To create a String object: stringObjectName = new String(string) To use a String object: 1. stringName. propertyName is one of the properties listed below. stringName.0 Navigator 3. added ability to pass strings among scripts in different windows or frames (in previous releases.propertyName 2.methodName(parameters) Parameters stringObjectName is the name of a new String object. italics methods String Object. world</STRIKE> See also blink.htm (35 of 44) [30/08/2003 9:34:32 PM] .htm <P><I>Hello. string is any string.0: added String() constructor (in previous releases. methodName is one of the methods listed below. stringName is the name of a String object or string variable.

The following statement creates a string variable: var last_name = "Schaefer" Example 2: String object properties. "SCHAEFER. The following statements evaluate to eight. "Netscape" or 'Netscape'.html'.htm The String object is a built-in JavaScript object.htm (36 of 44) [30/08/2003 9:34:32 PM] .open('string2.length last_name. Properties The String object has the following properties: Property Description length Reflects the length of the string prototype Lets you add properties to a String object." and "schaefer": last_name.toLowerCase() Example 3: Pass a string among scripts in different windows or frames.height=300') file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.toUpperCase() last_name. A string can be represented as a literal enclosed by single or double quotation marks.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. Methods The String object has the following methods: q q q q q q q q anchor method big blink bold charAt eval fixed fontcolor q q q q q q q fontsize indexOf italics lastIndexOflink method small split strike q q q q q q q sub substring sup toLowerCase toUpperCase toString valueOf Event handlers None. The following code creates two string variables and opens a second window: var lastName = new String("Schaefer") var firstName = new String ("Jesse") empWindow=window.'width=300. Examples Example 1: String variable.'window1'. for example.

sup() + " looks like. Causes a string to be displayed as a subscript. as if it were in a <SUB> tag.empFirstName=firstName empWindow.") document. Textarea object sub Method. the following code in the first window assigns values to the second window's variables: empWindow.htm (37 of 44) [30/08/2003 9:34:32 PM] . Examples The following example uses the sub and sup methods to format a string: var superText="superscript" var subText="subscript" document.empLastName) See also Text object.write("This is what a " + superText.empFirstName) alert('empLastName in empWindow is ' + empWindow. Method of String Implemented in Navigator 2.empLastName=lastName The following code in the first window displays the values of the second window's variables: alert('empFirstName in empWindow is ' + empWindow.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.") file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.html) creates two string variables. empLastName and empFirstName.htm If the HTML source for the second window (string2.write("<P>This is what a " + subText.sub() Parameters stringName is any string or a property of an existing object.0 Description Use the sub method with the write or writeln methods to format and display a string in a document. Syntax stringName.sub() + " looks like.

Method of Form object Implemented in Navigator 2.submit() Parameters formName is the name of any form or an element in the forms array.submit() file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.musicChoice. but a confirming dialog will tell them that they are about to give away private or sensitive information.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. It performs the same action as a submit button." as specified in the method property. news:. <P>This is what a <SUB>subscript</SUB> looks like. Examples The following example submits a form called musicChoice: document. Users can submit forms with such URLs by clicking a submit button. if the form's action is a mailto:. or snews: URL. This is for security purposes.htm The previous example produces the same output as the following HTML: This is what a <SUP>superscript</SUP> looks like. Submits a form. The submit method fails without notice. The submit method returns the data using either "get" or "post. Syntax formName. Use the submit method to send data back to an HTTP server. See also sup method submit method Method.htm (38 of 44) [30/08/2003 9:34:32 PM] .0 Description The submit method submits the specified form.

you also can submit it as follows: document. HTML syntax To define a submit button. use standard HTML syntax with the addition of JavaScript event handlers: <INPUT TYPE="submit" NAME="submitName" VALUE="buttonText" [onBlur="handlerText"] [onClick="handlerText"] [onFocus="handlerText"]> HTML attributes NAME="submitName" specifies the name of the Submit object.methodName(parameters) formName.htm (39 of 44) [30/08/2003 9:34:32 PM] . 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. submitName. and you can use this name when indexing the elements array. 3.elements[index]. See also Submit object. VALUE="buttonText" specifies the label to display on the button face. A submit button causes a form to be submitted. You can access this value using the value property.methodName(parameters) Parameters submitName is the value of the NAME attribute of a Submit object. Syntax To use a Submit object's properties and methods: 1. formName is either the value of the NAME attribute of a Form object or an element in the forms array.submit() See also the example for the Form object.htm If musicChoice is the first form created.propertyName submitName.forms[0].elements[index]. onSubmit event handler Submit object Object. A submit button on an HTML form. 4.propertyName formName. You can access this value using the name property. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.

added onBlur and onFocus event handlers. (This is a standard HTML feature.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. instead. The submit button's onClick event handler cannot prevent a form from being submitted. This action always loads a new page into the client. the form submits. If a form contains only one element.htm index is an integer representing a Submit object on a form or the name of a Submit object as specified by the NAME attribute. methodName is one of the methods listed below.htm (40 of 44) [30/08/2003 9:34:32 PM] . Clicking a submit button submits a form to the URL specified by the form's action property. added blur and focus methods Description A Submit object on a form looks as follows: Done A Submit object is a form element and must be defined within a <FORM> tag. then when the user enters a value and presses Return. if the action so specifies or is not specified.0: added type property.0 Navigator 3.) Properties The Submit object has the following properties: Property Description form property Specifies the form containing the Submit object name type value Reflects the NAME attribute Reflects the TYPE attribute Reflects the VALUE attribute Methods The Submit object has the following methods: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. use the form's onSubmit event handler or use the submit method instead of a Submit object. propertyName is one of the properties listed below. a Text object. Property of Form object Implemented in q q Navigator 2. See the examples for the Form object. it may be the same as the current page.

indexB is any integer from zero to stringName. <INPUT TYPE="submit" NAME="submitButton" VALUE="Done"> See also the examples for the Form object. See also Button object.substring(indexA. Syntax stringName.0 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. indexA is any integer from zero to stringName. Method of String Implemented in Navigator 2. indexB) Parameters stringName is any string or a property of an existing object. or a property of an existing object.htm (41 of 44) [30/08/2003 9:34:32 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.1.htm q q q blur click eval q q q focus toString valueOf Event handlers q q q onBlur onClick onFocus Examples The following example creates a Submit object called submitButton. submit method.length . Form object. Returns a subset of a String object. onSubmit event handler substring Method. The text "Done" is displayed on the face of the button.length. or a property of an existing object. Reset object.

substring(i+oldS.fullS) { // Replaces oldS with newS in the string fullS for (var i=0.write(anyString."Web".1.substring(3. The index of the first character is zero.3)) document.length .htm (42 of 44) [30/08/2003 9:34:32 PM] .length.htm Description Characters in a string are indexed from left to right.4)) //Displays "Netscap" document."Brave New World") suffixes Property.write(anyString.10)) Example 2. It will replace both individual characters and substrings. The function call at the end of the example changes the string "Brave New World" into "Brave New Web".substring(7.0)) //Displays "cap" document.substring(0. the substring method returns the subset starting with the character at indexA and ending with the character before indexB.length) == oldS) { fullS = fullS. If indexA is greater than indexB. the substring method returns the subset starting with the character before indexB and ending with the character at indexA. A string listing possible file suffixes (also known as file name extensions) for the MIME type.write(anyString.length.7)) document.i+oldS. The following example replaces a substring within a string. If indexA is equal to indexB.newS. The following example uses substring to display characters from the string "Netscape": var anyString="Netscape" //Displays "Net" document. function replaceString(oldS. i++) { if (fullS. Examples Example 1.write(anyString.length) } } return fullS } replaceString("World".write(anyString.i)+newS+fullS. the substring method returns the empty string.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.7)) //Displays "Netscape" document.fullS.8)) document. and the index of the last character is stringName. i<fullS.substring(0.substring(0.substring(i.substring(0. q q q If indexA is less than indexB.write(anyString. Syntax file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.write(anyString.substring(4.substring(0.

htm (43 of 44) [30/08/2003 9:34:32 PM] .htm navigator. Causes a string to be displayed as a superscript. Syntax stringName. the suffixes for the "audio/x-midi" MIME type are "mid. type properties sup Method. See also description. For example. as if it were in a <SUP> tag. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.mimeTypes[index]. midi".suffixes Parameters index is either an integer representing a MIME type supported by the client or a string containing the type of a MimeType object (from the type property). Property of MimeType Implemented in Navigator 3. Examples See the examples for the MimeType object.sup() Parameters stringName is any string or a property of an existing object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s. enabledPlugin. suffixes is a read-only property.0 Tainted? No Description The suffixes property is a string consisting of each valid suffix (typically three letters long) separated by commas.

sub() + " looks like.htm Method of String Implemented in Navigator 2.") document.write("This is what a " + superText.write("<P>This is what a " + subText. See also sub method [Next reference file] file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.0 Description Use the sup method with the write or writeln methods to format and display a string in a document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_s-s.htm (44 of 44) [30/08/2003 9:34:32 PM] .") The previous example produces the same output as the following HTML: This is what a <SUP>superscript</SUP> looks like. Examples The following example uses the sub and sup methods to format a string: var superText="superscript" var subText="subscript" document. <P>This is what a <SUB>subscript</SUB> looks like.sup() + " looks like.

function. In some cases. Use taint to mark data that otherwise is not tainted. Syntax taint(dataElementName) Parameters dataElementName is the property. Examples The following statement adds taint to a property so that a script cannot send it to another server without the end user's permission: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm (1 of 53) [30/08/2003 9:34:35 PM] . an unmarked reference to the value. Implemented in Navigator 3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. taint is added to the script's window. or. If omitted. In these cases. such as directory structures or user session history. instead. it returns a marked copy of the value. for objects. Adds tainting to a data element or script. You can add taint to the script's window by calling taint with no arguments. taint is added to the script itself. or object to taint. See "Tainting that results from conditional statements". control flow rather than data flow carries tainted information. taint does not modify its argument.htm [Previous reference file] taint Function. variable. JavaScript cannot pass tainted values on to any server without the end user's permission.0 Description Tainting prevents other scripts from passing information that should be secure and private.

taintEnabled method. false otherwise. Use taintEnabled to determine if data tainting is enabled.taintEnabled() Method of navigator Implemented in Navigator 3. The user enables or disables data tainting by using the environment variable NS_ENABLE_TAINT. JavaScript cannot pass tainted values on to any server without the end user's permission. Examples file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.defaultStatus) // taintedStatus now cannot be sent in a URL or form post without // the end user's permission See also domain property. taintEnabled returns true if data tainting is enabled.htm (2 of 53) [30/08/2003 9:34:35 PM] . Syntax navigator.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. untaint function. Specifies whether data tainting is enabled.htm taintedStatus=taint(window. "Using data tainting for security" taintEnabled Method.0 Description Tainting prevents other scripts from passing information that should be secure and private. such as directory structures or user session history.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. untaint functions. if (navigator. taint. "Using data tainting for security" tan Method. or a property of an existing object.htm (3 of 53) [30/08/2003 9:34:35 PM] .0 Description The tan method returns a numeric value that represents the tangent of the angle.taintEnabled()) { function1() } else function2() See also domain property. Syntax Math.htm The following code executes function1 if data tainting is enabled. Method of Math Implemented in Navigator 2.tan(number) Parameters number is a numeric expression representing the size of an angle in radians. Returns the tangent of a number. Examples file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. otherwise it executes function2.

PI/4. a string specifying the name of the window that responses go to after a form has been submitted. areaName is the value of the NAME attribute of an Area object.target Parameters formName is either the name of a form or an element in the forms0 array. it returns 0. asin. See also acos.9999999999999999. atan2. sin methods target Property.htm The following function returns the tangent of the variable x: function getTan(x) { return Math.target 3. cos. Property of Area object (see Link object). areaName. Syntax 1. formName. a string specifying the name of the window that displays the content of a clicked hypertext link. index is an integer representing a Link object or the name of a Link object as specified by the NAME attribute. Form object.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. links[index]. For form.target 2. Link object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.tan(x) } If you pass getTan the value Math. atan.htm (4 of 53) [30/08/2003 9:34:35 PM] . For link.

<AREA>.0: property of Area Tainted? No Description The target property initially reflects the TARGET attribute of the <A>. or series of numbers in a text field. Form object Text object Object. HTML syntax file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.musicInfo. if the string represents a window name.htm Implemented in q q Navigator 2. You can set target using a string. method properties.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Examples The following example specifies that responses to the musicInfo form are displayed in the msgWindow window: document. phrase. and <FORM> tags. The target property cannot be assigned the value of a JavaScript expression or variable. The user can enter a word.0 Navigator 3.target="msgWindow" See also For form: action.htm (5 of 53) [30/08/2003 9:34:35 PM] . encoding. A text input field on an HTML form. setting target overrides these attributes. You can set the target property at any time. however.

3. You can access this value using the defaultValue property. formName is either the value of the NAME attribute of a Form object or an element in the forms array. You can access this value using the name property.methodName(parameters) formName. and you can use this name when indexing the elements array. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.elements[index].methodName(parameters) Parameters textName is the value of the NAME attribute of a Text object. SIZE=integer specifies the number of characters the Text object can accommodate without scrolling. 2. textName. index is an integer representing a Text object on a form or the name of a Text object as specified by the NAME attribute. propertyName is one of the properties listed below.propertyName textName. use standard HTML syntax with the addition of JavaScript event handlers: <INPUT TYPE="text" NAME="textName" VALUE="textValue" SIZE=integer [onBlur="handlerText"] [onChange="handlerText"] [onFocus="handlerText"] [onSelect="handlerText"]> HTML attributes NAME="textName" specifies the name of the Text object. 4.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm (6 of 53) [30/08/2003 9:34:35 PM] .htm To define a Text object.propertyName formName. Syntax To use a Text object's properties and methods: 1.elements[index]. VALUE="textValue" specifies the initial value of the Text object.

(This is a standard HTML feature.0: added type property Description A Text object on a form looks as follows: Last name: Salamone A Text object is a form element and must be defined within a <FORM> tag.) Properties The Text object has the following properties: Property Description defaultValue Reflects the VALUE attribute form property Specifies the form containing the Text object name type value Reflects the NAME attribute Reflects the TYPE attribute Reflects the current value of the Text object's field Methods file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.value).0 Navigator 3. a Text object. Text objects can be updated (redrawn) dynamically by setting the value property (this. then when the user enters a value and presses Return.htm (7 of 53) [30/08/2003 9:34:35 PM] . Property of Form object Implemented in q q Navigator 2. If a form contains only one element.htm methodName is one of the methods listed below.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. the form submits.

<B>Last name:</B> <INPUT TYPE="text" NAME="last_name" VALUE="" SIZE=25> Example 2. The following example creates a Text object that is 25 characters long.toUpperCase()"> </FORM> See also the examples for the onBlur. Each object has a default value. Textarea object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. The text field appears immediately to the right of the words "Last name:". The following example creates two Text objects on a form. The text field is blank when the form loads. <FORM NAME="form1"> <BR><B>City: </B><INPUT TYPE="text" NAME="city" VALUE="Anchorage" SIZE="20" onFocus="this.htm The Text object has the following methods: q q q blur eval focus q q q select method toString valueOf Event handlers q q q q onBlur onChange onFocus onSelect Examples Example 1. String object. See also FileUpload object.select()"> <B>State: </B><INPUT TYPE="text" NAME="state" VALUE="AK" SIZE="2" onChange="this. Password object.htm (8 of 53) [30/08/2003 9:34:35 PM] . onChange. Form object. The state object has an onChange event handler that forces the value to uppercase. The city object has an onFocus event handler that selects all the text in the field when the user tabs to that field.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. onFocus.value=this. and onSelect event handlers.value.

In previous releases.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. optionName is the name of a Select object option created using the Option() constructor. optionName. you could set the text property but the new value was not reflected in the Select object. selectName. Property of Option object (see Select object).htm text property Property.0 Navigator 3. You can set the text property at any time and the text displayed by the option in the Select object changes.htm (9 of 53) [30/08/2003 9:34:35 PM] . Syntax 1.text 2. Tainted? Yes Description The text property initially reflects the text that follows an <OPTION> tag in a Select object. A string specifying the text that follows an <OPTION> tag in a Select object.text Parameters selectName is either the value of the NAME attribute of a Select object or an element in the elements array.0: The text property of the options array can be changed and the text displayed by the option in the Select object changes. index is an integer representing an option in a Select object. options array (see Select object) Implemented in q q Navigator 2. Examples file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.options[index].

htm (10 of 53) [30/08/2003 9:34:35 PM] . The for loop evaluates every option in the musicType Select object. i < document. the getChoice function returns the value of the text property for the selected option.musicType.musicForm.htm In the following example.options[i]. i++) { if (document.options[i]. or numbers.selected == true) { return document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. use standard HTML syntax with the addition of JavaScript event handlers: <TEXTAREA NAME="textareaName" ROWS="integer" COLS="integer" [onBlur="handlerText"] [onChange="handlerText"] [onFocus="handlerText"] file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.musicType.musicForm. The if statement finds the option that is selected.musicType.length. phrases.musicForm. A multiline input field on an HTML form. The user can use a textarea field to enter words.text } } return null } The previous example assumes that the Select object is similar to the following: <SELECT NAME="musicType"> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT> Textarea Object. HTML syntax To define a text area. function getChoice() { for (var i = 0.

textToDisplay specifies the initial value of the Textarea object. propertyName is one of the properties listed below. textareaName. 3. 4.htm [onSelect="handlerText"]> textToDisplay </TEXTAREA> HTML attributes NAME="textareaName" specifies the name of the Textarea object. formName is either the value of the NAME attribute of a Form object or an element in the forms array. Syntax To use a Textarea object's properties and methods: 1. ROWS="integer" and COLS="integer" define the physical size of the displayed input field in numbers of characters.methodName(parameters) Parameters textareaName is the value of the NAME attribute of a Textarea object. and you can use this name when indexing the elements array. methodName is one of the methods listed below.elements[index].elements[index].file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. You can access this value using the defaultValue property.propertyName textareaName.methodName(parameters) formName. Property of Form object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm (11 of 53) [30/08/2003 9:34:35 PM] .propertyName formName. and new lines are respected. 2. index is an integer representing a Textarea object on a form or the name of a Textarea object as specified by the NAME attribute. You can access this value using the name property. A Textarea allows only ASCII text.

It can hold up to 72 CDs under the lid and 20 videos in the drawer below. Textarea objects can be updated (redrawn) dynamically by setting the value property (this. To begin a new line in a Textarea object. A Textarea object is a form element and must be defined within a <FORM> tag.value).0 Navigator 3.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm (12 of 53) [30/08/2003 9:34:35 PM] . you can use a newline character.htm Implemented in q q Navigator 2. Windows is \r. then set the newline character accordingly. Properties The Textarea object has the following properties: Property Description defaultValue Reflects the VALUE attribute form property Specifies the form containing the Textarea object name type value Reflects the NAME attribute Specifies that the object is a Textarea object Reflects the current value of the Textarea object Methods file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.0: added type property Description A Textarea object on a form looks as follows: Our storage ottoman provides an attractive way to store lots of CDs and videos--and it's versatile enough to store other things as well. Although this character varies from platform to platform (Unix is \n. JavaScript checks for all newline characters before setting a string-valued property and translates them as needed for the user's platform. You could also enter a newline character programmatically--one way is to test the appVersion property to determine the current platform. and Macintosh is \n). See the appVersion property for an example.

textarea1. the Textarea object contains several lines of data." </SCRIPT> <FORM NAME="form1"> <INPUT TYPE="button" Value="Populate the textarea" onClick="document. The textarea field appears immediately below the word "Description:".form1. the Textarea object is populated with the value from the string variable. It can hold up to 72 CDs under the lid and 20 videos in the drawer below. <B>Description:</B> <BR><TEXTAREA NAME="item_description" ROWS=6 COLS=55> Our storage ottoman provides an attractive way to store lots of CDs and videos--and it's versatile enough to store other things as well.htm The Textarea object has the following methods: q q q blur eval focus q q q select method toString valueOf Event handlers q q q q onBlur onChange onFocus onSelect Examples Example 1. </TEXTAREA> Example 2. The result is three lines of text in the Textarea object. <SCRIPT> myString="This is line one. The following example creates a Textarea object that is six rows long and 55 columns wide.\rThis is line three.value=myString"> <P> <TEXTAREA NAME="textarea1" ROWS=6 COLS=55></TEXTAREA> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. The following example creates a string variable containing newline two characters for different platforms.\nThis is line two. When the user clicks the button. including one blank line.htm (13 of 53) [30/08/2003 9:34:35 PM] . When the form loads.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. title is a read-only property. See also Form object. the value of the title property is assigned to a variable called docTitle: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Syntax document.0 Tainted? Yes Description The title property is a reflection of the value specified within the <TITLE> and </TITLE> tags. onChange.htm See also the examples for the onBlur. Text object title Property. If a document does not have a title. and onSelect event handlers. String object. A string representing the title of a document. Password object. Examples In the following example. onFocus. the title property is null.title Property of document Implemented in Navigator 2.htm (14 of 53) [30/08/2003 9:34:35 PM] .

htm (15 of 53) [30/08/2003 9:34:35 PM] .netscape.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.title toGMTString Method. Method of Date Implemented in Navigator 2.toGMTString() In this example. today is a Date object: today.toGMTString() Parameters dateObjectName is either the name of a Date object or a property of an existing object. the toGMTString method converts the date to GMT (UTC) using the operating system's time-zone offset and returns a string value that is similar to the following form. The exact format depends on the platform.0 Description The exact format of the value returned by toGMTString varies according to the platform.htm var newWindow = window.com") var docTitle = newWindow.document. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Converts a date to a string.open("http://home. Syntax dateObjectName. using the Internet GMT conventions. Examples In the following example.

Using methods such as getHours.toLocaleString() Parameters dateObjectName is either the name of a Date object or a property of an existing object. 18 Dec 1995 17:28:35 GMT See also toLocaleString method toLocaleString Method. Examples In the following example. using the current locale's conventions.0 Description If you are trying to pass a date using toLocaleString. Converts a date to a string. getMinutes. be aware that different locales assemble the string in different ways.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Method of Date Implemented in Navigator 2. Syntax dateObjectName.htm Mon. and getSeconds gives more portable results.htm (16 of 53) [30/08/2003 9:34:35 PM] . today is a Date object: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.

0 Description The toLowerCase method returns the value of stringName converted to lowercase. Returns the calling string value converted to lowercase. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Syntax stringName. toLowerCase does not affect the value of stringName itself. The exact format depends on the platform.htm today.htm (17 of 53) [30/08/2003 9:34:35 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. 12/18/95 17:28:35 See also toGMTString method toLowerCase Method. toLocaleString returns a string value that is similar to the following form.toLowerCase() Parameters stringName is any string or a property of an existing object.toLocaleString() In this example. Method of String Implemented in Navigator 2.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. methodName is any method associated with the window object.propertyName top.methodName top. 3. which is a "document window" or "Web Browser window. The top property is a synonym for the top-most Navigator window. 2. status.htm Examples The following example displays the lowercase string "alphabet": var upperText="ALPHABET" document. 4.write(upperText. Property of window object Implemented in file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm (18 of 53) [30/08/2003 9:34:35 PM] . or length. top.frameName top. frameName and frames[index] are ways to refer to frames.frames[index] Parameters propertyName is defaultStatus." Syntax 1.toLowerCase()) See also toUpperCase method top Property.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm NAME="childFrame2"> <FRAME SRC=child3.0 Tainted? No Description The top property refers to the top-most window that contains frames or nested framesets.htm NAME="childFrame1"> <FRAME SRC=child2. When the top-most ancestor is defined as follows.htm NAME="childFrame3"> </FRAMESET> The following example sets the background color of a frame called myFrame to red. The value of the top property is <object objectReference> where objectReference is an internal reference.bgColor="red" toString Method.document.myFrame. top. The top property is read-only. top.length specifies the number of frames contained within the top-most ancestor window. Examples The statement top. myFrame is a child of the top-most ancestor window. Returns a string representing the specified object. The statement top.40%.close() closes the top-most ancestor window. Use the top property to refer to this ancestor window.30%"> <FRAME SRC=child1.htm Navigator 2.length returns three: <FRAMESET COLS="30%.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm (19 of 53) [30/08/2003 9:34:35 PM] .

Link.write(theDog) document. For example. Implemented in Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. numberObjectName is the Number object to convert to a string.write("The dog is " + theDog) You can use toString within your own code to convert an object into a string. and you can create your own function to be called in place of the default toString method. the following examples require theDog to be represented as a string: document. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm Syntax objectName. for history.toString([radix]) Parameters objectName is the object to convert to a string. and any form input element.0 Navigator 3. location. Method of toString is a method of all objects.htm (20 of 53) [30/08/2003 9:34:35 PM] . No for all other objects Description Every object has a toString method that is automatically called when it is to be represented as a text value or when an object is referenced in a string concatenation.0: added radix Tainted? Yes.toString() numberObjectName. radix is an integer between 2 and 16 specifying the base to use for representing numeric values.

<IMG NAME="sealife" SRC="images\seaotter. JavaScript automatically calls the objectToString function. where type is the object type or the name of the constructor function that created the object. if the following Image object named "sealife" exists. which JavaScript calls whenever it needs to convert an object to a string. If an object has no string value and no user-defined toString method.breed.name=name this. toString returns "[object type]".name + " is [" for (var prop in this) ret += " " + prop + " is " + this[prop] + "."Lab". The toString method takes no arguments and should return a string.toString() returns [object Image].prototype. Suppose you have an object type Dog and you want to create a toString method for it."girl") The following code creates objectToString. For example.color.gif" ALIGN="left" VSPACE="10"> User-defined toString methods You can create a function to be called in place of the default toString method. sealife. The toString method you create can be any value you want.sex) { this.toString = objectToString With the preceding code in place.htm (21 of 53) [30/08/2003 9:34:35 PM] .breed=breed this.sex=sex } theDog = new Dog("Gabby".htm Built-in toString methods Every object type has a built-in toString method. the function that will be used in place of the default toString method. The following code defines the Dog object type and creates theDog. function objectToString() { var ret = "Object " + this." return ret + "]" } The following code assigns the user-defined function to the object's toString method: Dog.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.".color=color this. but it will be most useful if it carries information about the object. which returns the following string: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. any time theDog is used in a string context. an object of type Dog: function Dog(name. of the form "property = value. This function generates a string containing each property."chocolate".

which returns the following string: function Dog(name. toString is function objectToString() { var ret = "Object " + this. } return ret + "]". } file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. curly braces.Apr Boolean objects and toString For Boolean objects and values.toString() + "<BR>") Functions and toString For Function objects.name = name."Apr") document.write("monthNames. but you can invoke it yourself as follows: alert(theDog. and function body."Mar". the following code creates an array and uses toString to convert the array to a string while writing output. } . flag. sex) { this.breed = breed. the built-in toString method joins the array and returns one string containing each array element separated by commas.toString() is Jan. flag = new Boolean(true) document. the argument list.". For example.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm Object Gabby is [ name is Gabby.] An object's toString method is usually invoked by JavaScript. In the following code.sex = sex. suppose you create the function Dog shown in "User-defined toString methods". color is chocolate. This string includes the function keyword.toString()) The output is as follows: monthNames. this.toString() is " + monthNames.write("flag.Mar. for (var prop in this) { ret += " " + prop + " is " + this[prop] + ".Feb. breed is Lab. JavaScript automatically calls the toString function. breed."Feb".htm (22 of 53) [30/08/2003 9:34:35 PM] .name + " is [". the built-in toString method decompiles the function back into the JavaScript source that defines the function. sex is girl.toString() is " + flag. Any time Dog is used in a string context.toString returns "true". the built-in toString method returns "true" or "false" depending on the value of the boolean object. For example. this. this.color = color. color. var monthNames = new Array("Jan".toString()) Arrays and toString For Array objects.

write("location. x.toString(10).toString() + "<BR>") // The next line causes an error document.write("Decimal: ".toString() is " + 45.gif" ALIGN="left" VSPACE="10"> Because the Image object itself has no string equivalent. x < 10.toString(2). Suppose the following Image object named "sealife" exists: <IMG NAME="sealife" SRC="images\seaotter.toString() is " + location.html Example 2: Object with no string value.toString() + "<BR>") Examples Example 1: The location object.toString() will return the following: [object Image] Example 3: The radix parameter. document.write("howMany. The following example prints the string equivalent of the current location.htm Numbers and toString You can use toString on numeric values. x.htm (23 of 53) [30/08/2003 9:34:35 PM] .toString() + "<BR>") The output is as follows: file:///C|/TEMP/myprog.write("45.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. " Binary: ". for (x = 0. The following example prints the string equivalents of the numbers 0 through 9 in decimal and binary. but not on numeric literals: // The next two lines are valid var howMany=10 document. sealife. x++) { document.toString() is " + howMany. "<BR>") } The preceding example produces the following output: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.

htm Decimal: Decimal: Decimal: Decimal: Decimal: Decimal: Decimal: Decimal: Decimal: Decimal: 0 1 2 3 4 5 6 7 8 9 Binary: Binary: Binary: Binary: Binary: Binary: Binary: Binary: Binary: Binary: 0 1 10 11 100 101 110 111 1000 1001 See also prototype property. valueOf method toUpperCase Method.0 Description file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Returns the calling string value converted to uppercase. Syntax stringName.toUpperCase() Parameters stringName is any string or a property of an existing object.htm (24 of 53) [30/08/2003 9:34:35 PM] . Method of String Implemented in Navigator 2.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.

checkbox. or <TEXTAREA> tags. Reset object. the a string specifying the name of the MIME type. password. select.htm (25 of 53) [30/08/2003 9:34:36 PM] . <SELECT>. toUpperCase does not affect the value of stringName itself. text. For form elements created with the <INPUT>. Password object. index is either an integer representing a MIME type supported by the client or a string containing the type of a MimeType object (from the type property). hidden. For MimeType objects.type 2. Property of Button object. Examples The following example displays the string "ALPHABET": var lowerText="alphabet" document.mimeTypes[index]. a string specifying the type of form element. radio. reset. MimeType object. Radio object. Checkbox object. Hidden object.toUpperCase()) See also toLowerCase method type Property.htm The toUpperCase method returns the value of stringName converted to uppercase.write(lowerText.type Parameters objectName is either the value of the NAME attribute of a form element object (button. Syntax 1.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. navigator. objectName. submit. FileUpload object. file upload. Submit object. or textarea) or an element in the elements array. Text object. Textarea object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Select object.

For form elements. i++) { file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.elements. i < document.0 Tainted? No Description For MimeType objects.htm (26 of 53) [30/08/2003 9:34:36 PM] .htm Implemented in Navigator 3. the value of the type property is assigned as follows: HTML element INPUT TYPE="button" INPUT TYPE="file" INPUT TYPE="hidden" INPUT TYPE="radio" INPUT TYPE="reset" INPUT TYPE="submit" INPUT TYPE="text" SELECT SELECT MULTIPLE TEXTAREA type is a read-only property.form1. Value of type property "button" "file" "hidden" "radio" "reset" "submit" "text" "select-one" "select-multiple" "textarea" INPUT TYPE="checkbox" "checkbox" INPUT TYPE="password" "password" Examples The following example writes the value of the type property for every element on a form.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. the type property is a unique string that distinguishes the MIME type from all others. for (var i = 0.length. for example "video/mpeg" or "audio/x-wav".

Syntax unescape("string") Parameters string is a string or a property of an existing object. where integer is a number between 0 and 255 (decimal) "hex".writeln("<BR>type is " + document. The unescape function is a top-level JavaScript function not associated with any object.form1.htm (27 of 53) [30/08/2003 9:34:36 PM] . suffixes properties unescape Function. enabledPlugin. where hex is a number between 0x0 and 0xFF (hexadecimal) Implemented in Navigator 2.type) } See also the examples for the MimeType object.0 Description The string returned by the unescape function is a series of characters in the ISO Latin-1 character set.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm document. Returns the ASCII string for the specified value.elements[i]. See also For MimeType objects: description. Examples The following example returns "&": file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. containing characters in either of the following forms: q q "%integer".

Removes tainting from a data element or script.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. variable. If omitted. JavaScript cannot pass tainted values on to any server without the end user's permission. such as directory structures or user session history. only data that has the script's taint code or has the identity (null) taint code). Syntax untaint(dataElementName) Parameters dataElementName is the property. Use untaint to clear tainting that marks data that should not to be sent by other scripts to different servers.0 Description Tainting prevents other scripts from passing information that should be secure and private. function.htm (28 of 53) [30/08/2003 9:34:36 PM] . Implemented in Navigator 3. If you use untaint with a data element from another server's script (or file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. or object to remove tainting from. taint is removed from the script itself.htm unescape("%26") The following example returns "!#": unescape("%21%23") See also escape function untaint Function. A script can untaint only data that originated in that script (that is.

untaint does not modify its argument. taint function. or. instead.URL Property of document Implemented in Navigator 2.htm any data that you cannot untaint). for objects. if the window contains taint only from the current window. You can remove taint from the script's window by calling untaint with no arguments.defaultStatus) // untaintedStatus can now be sent in a URL or form post by other // scripts See also domain property. untaint returns the data without change or error.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. an unmarked reference to the value. Syntax document. "Using data tainting for security" URL Property.0 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. A string specifying the complete URL of the document.htm (29 of 53) [30/08/2003 9:34:36 PM] . See "Tainting that results from conditional statements". Examples The following statement removes taint from a property so that a script can send it to another server: untaintedStatus=untaint(window. control flow rather than data flow carries tainted information. taint is added to the script's window. In these cases. it returns an unmarked copy of the value. In some cases.

href is set to when you load the document.write("The current URL is " + document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. but redirection may change location. Examples The following example displays the URL of the current document: document. URL is a string-valued property that usually matches what window.location.URL) See also href userAgent Property. Syntax navigator.htm Tainted? Yes Description URL is a read-only property of document containing the full URL of the document. A string representing the value of the user-agent header sent in the HTTP protocol from client to server.0 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm (30 of 53) [30/08/2003 9:34:36 PM] .href.userAgent Property of navigator Implemented in Navigator 2.

userAgent is " + navigator. min] [.0.userAgent is Mozilla/2. sec]) Parameters file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. day [. javaEnabled properties UTC Method. month. Returns the number of milliseconds in a Date object since January 1.userAgent) For Navigator 2. this displays the following: The value of navigator.UTC(year. 00:00:00.htm (31 of 53) [30/08/2003 9:34:36 PM] . Universal Coordinated Time (GMT). appName. appVersion.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Examples The following example displays userAgent information for the Navigator: document. Syntax Date. I) See also appCodeName. 1970.write("The value of navigator.0 (Win16. hrs] [. userAgent is a read-only property.htm Tainted? No Description Servers use the value sent in the user-agent header to identify the client.

Method of Date Implemented in Navigator 2. sec is seconds between zero and 59. 11. 00:00:00. 0)) See also parse method file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm year is a year after 1900. 0. Because UTC is a static method of Date. date is a day of the month between one and 31. Examples The following statement creates a Date object using GMT instead of local time: gmtDate = new Date(Date.htm (32 of 53) [30/08/2003 9:34:36 PM] .0 Description UTC takes comma-delimited date parameters and returns the number of milliseconds since January 1.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. hrs is hours between zero and 23. Universal Coordinated Time (GMT). 1970. min is minutes between zero and 59. you always use it as Date. rather than as a method of a Date object you created. 0. 1. month is a month between zero and 11.UTC(96.UTC().

objectName. Submit. Text. Textarea object options array (see Select object) Implemented in q q Navigator 2.[index]. 3. index is an integer representing a radio button in a Radio object or an option in a Select object. Hidden object. Property of q q Button object.value selectName.value radioName[index]. Password object. A string that is related to the VALUE attribute of its object. Reset object.value Parameters objectName is either the value of the NAME attribute of a Hidden. Option object (see Select object). 5. Reset.htm (33 of 53) [30/08/2003 9:34:36 PM] . Syntax 1.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.0 Navigator 3. Textarea. Text object. fileUploadName is either the value of the NAME attribute of a FileUpload object or an element in the elements array. Checkbox object.htm value Property. optionName is the name of a Select object option created using the Option() constructor. selectName is either the value of the NAME attribute of a Select object or an element in the elements array. Submit object. Radio object.options. 4.value optionName. radioName is the value of the NAME attribute of a Radio object. Password. Button.0: property of FileUpload. Option file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.value fileUploadName. 2. FileUpload object. or Checkbox object or an element in the elements array.

" For submit. Do not confuse the value property with the name property. it is used to reference the objects programmatically." The value property is not displayed on-screen but is returned to the server if the radio button or checkbox is selected. The checked property determines the selection state of the object. FileUpload objects file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. and the defaultChecked property determines the default selection state. When a VALUE attribute is not specified in HTML. Reset. it is the string "Submit Query. For reset. Button. The name property is not displayed on-screen. the value property differs for each object: q q q For button. The text that is displayed is specified following the <INPUT TYPE="checkbox"> or the <INPUT TYPE="radio"> tag.htm Tainted? Yes Description The value property differs for every object. This string is displayed on the face of the button. it is the string "Reset. the value property is a string that reflects it. value is a read-only property. and Submit objects When a VALUE attribute is specified in HTML. it is an empty string. the value property is a string that evaluates to "on. When a VALUE attribute is not specified in HTML." These strings are displayed on the faces of the buttons.htm (34 of 53) [30/08/2003 9:34:36 PM] . Do not confuse the value property with the selection state of the object or the text that is displayed next to each checkbox and radio button.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. the value property is a string that reflects it. You can set the value property at any time. Checkbox and Radio objects When a VALUE attribute is specified in HTML.

but the value is always displayed as asterisks. you cannot evaluate it accurately unless data tainting is enabled. The value of this property changes when a user or a program modifies the field. and Textarea objects The value property is a string that initially reflects the VALUE attribute. The value of this property changes when a user or a program modifies the field. The text that is displayed in each option is file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. JavaScript returns the current value. This value is not displayed onscreen. options array The value property is a string that initially reflects the VALUE attribute. See "Using data tainting for security". The display of the Text and Textarea objects updates immediately when you set the value property.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. and the defaultSelected property determines the default selection state. value is a read-only property. The value of this property can change when a program modifies it. Text.htm The value property is a string that reflects the current value of a FileUpload object's field. the value property is a string that initially reflects the VALUE attribute. This string is displayed in the text and textarea fields.htm (35 of 53) [30/08/2003 9:34:36 PM] . The value of this property can change when a program modifies it. Hidden. You can set the value property at any time. but is returned to the server if the option is selected. The selected and selectedIndex properties determine which options are selected. Do not confuse the value property with the selection state of the Select object or the text that is displayed as an option. You can set the value property at any time. Select object options For Select object options created using the Option() constructor. This string is represented by asterisks in the Password object field. If a user interactively modifies the value in the password field. The value property is not displayed on-screen but is returned to the server if the option is selected. If you programmatically set the value property and then evaluate it. You can set the value property at any time. Password object The value property is a string that initially reflects the VALUE attribute. Use the value property to obtain the file name that the user typed into a FileUpload object.

value is " + document.document.write("helpButton.value +"<BR>") } msgWindow.radioObj[i]. i < document.value + "<BR>") msgWindow.close() } file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.value + "<BR>") msgWindow.valueTest.htm (36 of 53) [30/08/2003 9:34:36 PM] .close() } This example displays the following values: Query Submit Reset Help The previous example assumes the buttons have been defined as follows: <INPUT TYPE="submit" NAME="submitButton"> <INPUT TYPE="reset" NAME="resetButton"> <INPUT TYPE="button" NAME="helpButton" VALUE="Help"> The following function evaluates the value property of a group of radio buttons and displays it in the msgWindow window: function valueGetter() { var msgWindow=window.document.resetButton.value + "<BR>") msgWindow. Examples The following function evaluates the value property of a group of buttons and displays it in the msgWindow window: function valueGetter() { var msgWindow=window.write("submitButton.document.valueTest.valueTest.open("") for (var i = 0.write("resetButton.document.helpButton.htm specified by its text property.length.open("") msgWindow.write ("The value of radioObj[" + i + "] is " + document. i++) { msgWindow.radioObj.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.value is " + document.valueTest.document.document.valueTest.submitButton.value is " + document.

htm This example displays the following values: on on on on The previous example assumes the buttons have been defined as follows: <BR><INPUT <BR><INPUT <BR><INPUT <BR><INPUT TYPE="radio" TYPE="radio" TYPE="radio" TYPE="radio" NAME="radioObj">R&B NAME="radioObj" CHECKED>Soul NAME="radioObj">Rock and Roll NAME="radioObj">Blues See also q q q q For hidden. reset. password. Syntax objectName. Returns the primitive value of the specified object. text.valueOf() Parameters objectName is the object to converted to a value. and submit: name property For options array: defaultSelected property. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Method of valueOf is a method of all objects. selected property.htm (37 of 53) [30/08/2003 9:34:36 PM] . selectedIndex property. defaultChecked properties valueOf Method. text property For checkbox and radio: checked. and textarea: defaultValue property For button.

typeOf funObj returns "object".valueOf() returns "function".valueOf = new Function(functionText) file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. but typeOf funObj. For example. The following code assigns a user-defined function to the object's valueOf method: myNumberType.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. If an object has no primitive value.0 Description Every object has a valueOf method that is automatically called when it is to be represented as a primitive value. JavaScript automatically invokes it when encountering an object where a primitive value is expected. and you can create your own function to be called in place of the default valueOf method. which JavaScript calls whenever it needs to convert an object to a primitive value. You rarely need to invoke the valueOf method yourself. String associated with the object. Built-in valueOf methods Every object type has a built-in valueOf method. Most other objects have no primitive value. User-defined valueOf methods You can create a function to be called in place of the default valueOf method. The valueOf method takes no arguments. Suppose you have an object type myNumberType and you want to create a valueOf method for it. Function reference associated with the object.htm (38 of 53) [30/08/2003 9:34:36 PM] . You can use valueOf within your own code to convert an object into a primitive value. valueOf returns the object itself. Object type Value returned by valueOf Number Boolean String Function Primitive numeric value associated with the object. The valueOf method is most useful for the following object types.htm Implemented in Navigator 3.prototype. Primitive boolean value associated with the object.

valueOf() toString vs. but you can invoke it yourself as follows: myNumber. or function.0 Tainted? file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. A string specifying the color of visited links. But many objects do not convert to number. any time an object of type myNumberType is used in a context where it is to be represented as a primitive value.vlinkColor Property of document Implemented in Navigator 2. See also parseInt function. For information on toString.htm With the preceding code in place. valueOf for String objects Objects in string contexts convert via the toString method. see toString. toString method. JavaScript automatically calls the function defined in the preceding code. if only "[object type]". which is different from String objects converting to string primitives via valueOf. An object's valueOf method is usually invoked by JavaScript. All string objects have a string conversion. boolean.htm (39 of 53) [30/08/2003 9:34:36 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Syntax document. "typeof" vlinkColor Property.

htm No Description The vlinkColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in "Color values". If you express the color as a hexadecimal RGB triplet. bgColor. the hexadecimal RGB values for salmon are red=FA.htm (40 of 53) [30/08/2003 9:34:36 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. You cannot set this property after the HTML source has been through layout. and blue=72. you must use the format rrggbb.vlinkColor="aqua" The following example sets the color of active links to aqua using a hexadecimal triplet: document. fgColor. The default value of this property is set by the user on the Colors tab of the Preferences dialog box. green=80. linkColor properties vspace Property. so the RGB triplet for salmon is "FA8072.vspace file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. This property is the JavaScript reflection of the VLINK attribute of the <BODY> tag. For example. Syntax imageName. A string specifying a margin in pixels between the top and bottom edges of an image and the surrounding text." Examples The following example sets the color of visited links to aqua using a string literal: document.vlinkColor="00FFFF" See also alinkColor. which is displayed by choosing General Preferences from the Options menu.

A string specifying the width of an image in pixels. Syntax file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. height.0 Tainted? No Description The vspace property reflects the VSPACE attribute of the <IMG> tag. hspace.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm (41 of 53) [30/08/2003 9:34:36 PM] . For images created with the Image() constructor.htm Parameters imageName is either the name of an Image object or an element in the images array. vspace is a read-only property. the value of the vspace property is 0. See also border. Examples See the examples for the height property. Property of Image Implemented in Navigator 3. width properties width Property.

Property of Image Implemented in Navigator 3.0 Tainted? No Description The width property reflects the WIDTH attribute of the <IMG> tag.htm imageName. width is a read-only property. Examples See the examples for the height property.width Parameters imageName is either the name of an Image object or an element in the images array. vspace properties window object file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm (42 of 53) [30/08/2003 9:34:36 PM] . width of the image. not the displayed. height.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. See also border. hspace. the value of the width property is the actual. For images created with the Image() constructor.

"windowName" [. 2. 9. [onBlur="handlerText"] [onFocus="handlerText"] [onLoad="handlerText"] [onUnload="handlerText"]> </BODY> <FRAMESET ROWS="rowHeightList" COLS="columnWidthList" [onBlur="handlerText"] [onFocus="handlerText"] [onLoad="handlerText"] [onUnload="handlerText"]> [<FRAME SRC="URL" NAME="frameName">] </FRAMESET> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.propertyName window.htm (43 of 53) [30/08/2003 9:34:36 PM] . Syntax To define a window. The top-level object for each document. 8.methodName(parameters) windowVar..methodName(parameters) parent..propertyName self."windowFeatures"]) For details on defining a window. 5. To use a window object's properties and methods: 1. use the open method: windowVar = window. 12. 4.propertyName top. and history object group. 10.open("URL".htm Object. 3. window.propertyName parent.methodName(parameters) top.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. see the open (window object) method. 7.methodName(parameters) propertyName methodName(parameters) To define an event handler for a window object. location.methodName(parameters) self. use the <BODY> or <FRAMESET> tags: <BODY . 11.propertyName windowVar. 6.

methodName is one of the methods listed below.0 Navigator 3. and onFocus event handlers Description file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. and scroll methods. added blur. placing an onBlur or onFocus event handler in a <FRAMESET> tag has no effect. Use this variable when referring to a window's properties.onerror=errorHandler For information on specifying the onError event handler. For information on the <BODY> and <FRAMESET> tags. windowName is the window name to use in the TARGET attribute of a <FORM> or <A> tag. Please see the release notes (after starting Netscape. To define an onError event handler for a window object: window.htm Note On some platforms. Property of None Implemented in q q Navigator 2.0: added closed and opener properties. the name of an error-handling function. choose Release Notes from the Help menu). see onError event handler. errorHandler is the keyword null. or a variable or property that contains null or a valid function reference.htm (44 of 53) [30/08/2003 9:34:36 PM] . methods. and containership.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. focus. propertyName is one of the properties listed below. see the document and Frame objects. added onBlur. onError. Parameters windowVar is the name of a new window.

a call to close() without specifying an object name is equivalent to document. For example. The self and window properties are synonyms for the current window. you do not have to reference the name of the window when you call its methods and assign its properties. and close() is a valid method call. you must specify window. and you can optionally use them to refer to the current window.location instead of simply using location.open() or window. a call to location without specifying an object name is equivalent to document.status from a form called status. you can close the current window by calling either window. When you reference the location object within an event handler. You can reference a window's Frame objects in your code by using the frames array. status="Jump to a new location" is a valid property assignment. For example. Due to the scoping of static objects in JavaScript. Properties The window object has the following properties: Property closed defaultStatus frames Description Specifies whether a window has been closed Reflects the default message displayed in the window's status bar An array reflecting all the frames in a window file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Frame objects are also windows. which is a synonym for document.close(). Windows lack event handlers until some HTML is loaded into them containing a <BODY> or <FRAMESET> tag. The frames array contains an entry for each frame in a window with a <FRAMESET> tag. You can use these properties to make your code more readable or to disambiguate the property reference self. Because the existence of the current window is assumed. See the properties and methods listed below for more examples. when you open or close a window within an event handler.URL.close(). Due to the scoping of static objects in JavaScript.location. See the top and parent properties. and parent refers to a window containing a frameset.close() instead of simply using open() or close(). However. top refers to the top-most Navigator window.htm (45 of 53) [30/08/2003 9:34:36 PM] .htm The window object is the top-level object in the JavaScript client hierarchy.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.close() or self. The top and parent properties are also synonyms that can be used in place of the window name. you must specify window.

htm (46 of 53) [30/08/2003 9:34:36 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm length name opener parent self status top Reflects the number of frames in a parent window Reflects the windowName argument Specifies the window name of the calling document when a window is opened using the open method A synonym for the windowName argument and refers to a window containing a frameset A synonym for the windowName argument and refers to the current window Specifies a priority or transient message in the window's status bar A synonym for the windowName argument and refers to the top-most Navigator window window property A synonym for the windowName argument and refers to the current window The following objects are also properties of the window object: q q q q document Frame history object location Methods The window object has the following methods: q q q q q q q alert blur clearTimeout close (window object) confirm eval focus q q q q q q open (window object) prompt scroll setTimeout toString valueOf Event handlers q q q q onBlur onError onFocus onLoad file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.

write to the message window.width=250.name + "</B>") document. and close window2. 'scrollbars=yes.htm q onUnload Examples In the following example.writeln('Hey there').file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. height=300')"> <P><INPUT TYPE="button" VALUE="Write to the message window" onClick="window3. window2.document.htm (47 of 53) [30/08/2003 9:34:36 PM] . window3.close()"> <P><INPUT TYPE="button" VALUE="Close window2" onClick="window2.width=175. "scrollbars=yes. which defines the content for window2.document. contains the following code: <HTML> <HEAD> <TITLE>Window object example: Window 1</TITLE> </HEAD> <BODY BGCOLOR="antiquewhite"> <SCRIPT> window2=open("win2.html. the document in the top window opens a second window. which defines the frames for the first window. win1. and defines pushbuttons that open a message window.writeln("<BR><B>The second window is named: " + window2.html". contains the following code: <HTML> <HEAD> file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.close()"> </FORM> </BODY> </HTML> win2.writeln("<B>The first window has no name: " + window.html. The onLoad and onUnload event handlers of the document loaded into window2 display alerts when the window opens and closes.name + "</B>") </SCRIPT> <FORM NAME="form1"> <P><INPUT TYPE="button" VALUE="Open a message window" onClick = "window3=window.'messageWindow'.open(''. height=400") document.close()"> <P><INPUT TYPE="button" VALUE="Close the message window" onClick="window3. close the message window."secondWindow".

propertyName is the length or name property when the calling window refers to a Frame object.propertyName 2.methodName Parameters propertyName is the defaultStatus.name + ': I\'m closing')"> <B>Some numbers</B> <UL><LI>one <LI>two <LI>three <LI>four</UL> </BODY> </HTML> See also the example for the Frame object. window.name + ': Hello.htm <TITLE>Window object example: Window 2</TITLE> </HEAD> <BODY BGCOLOR="oldlace" onLoad="alert('Message from ' + window.htm (48 of 53) [30/08/2003 9:34:36 PM] . window. Syntax 1. Frame objects window property Property. status. The window property is a synonym for the current window or frame.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.')" onUnload="alert('Message from ' + window. methodName is any method associated with the window object. Property of file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. or name property when the calling window refers to a window object. See also document. World. length.

window. Examples In the following example.name and self. return true"> Go!</A> See also file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.htm (49 of 53) [30/08/2003 9:34:36 PM] . Although you can use the window property as a synonym for the current frame.name both specify the name of the current frame. <A HREF="" onClick="this. This usage disambiguates the status property of the current window from a form called "status" within the current window.status is used to set the status property of the current window. You can also use the window property to make your code more readable.0 Tainted? No Description The window property refers to the current window or frame. but self. The value of the window property is <object nameAttribute> where nameAttribute is the NAME attribute if window refers to a frame. or an internal reference if window refers to a window.status='Pick a random URL' . window.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. The window property is read-only. Use the window property to disambiguate a property of the window object from a form or form element of the same name. For example.name is easier to understand.href=pickRandomURL()" onMouseOver="window. window object Implemented in Navigator 2.htm Frame object. your code is more readable if you use the self property.

However. Syntax document. or logicals. except the write method does not append a newline character to the end of the output.open() method in the event handler.htm (50 of 53) [30/08/2003 9:34:36 PM] . The write method is the same as the writeln method. the HTML parser reads file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. .expression2].write(expression1 [.htm self property write Method.0 Navigator 3. Writes one or more HTML expressions to a document in the specified window.[. You can specify any JavaScript expression with the write method.. Use the write method within any <SCRIPT> tag or within an event handler. Event handlers execute after the original document closes. so the write method will implicitly open a new document of mimeType text/html if you do not explicitly issue a document.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Method of document Implemented in q q Navigator 2. strings. You can use the write method to generate HTML and JavaScript code.expressionN]) Parameters expression1 through expressionN are any JavaScript expressions or the properties of existing objects.0: users can print and save generated HTML using the commands on the File menu Description The write method displays any number of expressions in a document window. including numerics..

. Examples In the following example. and viewing generated HTML In Navigator 3. saving. a numeric.write(" This some text inside a comment. " testing ". msgWindow. the method displays "Minor..document.write(status = (age >= 18) ? "Adult" : "Minor") file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. If the value of the variable age is less than 18. the write method takes several arguments..document.document. the write method takes two arguments. The first argument is an assignment expression.'window2') beginComment="\<!--" endComment="--\>" window2.0. users can print and save generated HTML using the commands on the File menu. The following example shows a view-source: URL: view-source:wysiwyg://0/file:/c|/temp/genhtml. the following write method generates a comment and writes it to window2: window2=window. and a variable: var mystery = "world" // Displays Hello world testing 123 msgWindow.write(mystr = "Hello " + "world.document.html For information on specifying the view-source: protocol in the location object. mystery. including strings. //Displays Hello world. To view HTML code that was generated with JavaScript write and writeln methods. the method displays "Adult. the user must specify the view-source: protocol." If the value of age is greater than or equal to 18. and the second argument is a string literal. so you might have to escape some characters.write(endComment) Printing.write("Hello ". the write method takes a single argument that is a conditional expression.htm (51 of 53) [30/08/2003 9:34:36 PM] . the content displayed is that of the wysiwyg: URL. For example. ") window2.") In the following example.document. 123) In the following example. see the location object.htm the generated code as it is being written." msgWindow.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z..open(''.document. If the user chooses Document Source or Frame Source from the View menu.write(beginComment) window2.

or logicals..expressionN]) Parameters expression1 through expressionN are any JavaScript expressions or the properties of existing objects.htm See also close (document object). open (document object). except within certain tags such as <PRE>. Method of document Implemented in q q Navigator 2.writeln(expression1 [. Syntax document. . except the writeln method appends a newline character to the end of the output. writeln methods writeln Method.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.0 Navigator 3.0: users can print and save generated HTML using the commands on the File menu Description The writeln method displays any number of expressions in a document window.. strings. Use the writeln method within any <SCRIPT> tag or within an event handler. including numerics. You can specify any JavaScript expression.[.htm (52 of 53) [30/08/2003 9:34:36 PM] . The writeln method is the same as the write method. HTML ignores the newline character. Event handlers execute after file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Writes one or more HTML expressions to a document in the specified window and follows them with a newline character.expression2].

See also close (document object). write methods file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z.open() method in the event handler.htm (53 of 53) [30/08/2003 9:34:36 PM] .htm the original document closes. open (document object).file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/ref_t-z. Examples All the examples used for the write method are also valid with the writeln method. so the writeln method will implicitly open a new document of mimeType text/html if you do not explicitly issue a document.

methods.htm Object summary he following table lists each object and its properties.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary. Object Anchor anchors array Applet applets array Area Properties none length none length hash host hostname href pathname port protocol search target length prototype form name type value Methods none none none none Event handlers none none none onMouseOut onMouseOver All public methods of the applet none Array join reverse sort blur click focus none Button onBlur onClick onFocus onBlur onClick onFocus Checkbox checked blur defaultChecked click form focus name type value file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary. and valueOf methods. toString.htm (1 of 7) [30/08/2003 9:34:36 PM] . and event handlers. Note that all objects have the eval.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary.htm (2 of 7) [30/08/2003 9:34:36 PM] .htm Date prototype getDate getDay getHours getMinutes getMonth getSeconds getTime getTimezoneOffset getYear parse setDate setHours setMinutes setMonth setSeconds setTime setYear toGMTString toLocaleString toString UTC valueOf close open write writeln none document alinkColor Anchor anchors Applet applets Area bgColor cookie domain embeds fgColor Form forms Image images lastModified linkColor Link links referrer title none file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary.

htm (3 of 7) [30/08/2003 9:34:36 PM] .htm URL vlinkColor FileUpload form name type value action Button Checkbox elements encoding FileUpload Hidden length method name Password Radio Reset Select Submit target Text Textarea length frames name length parent self window length name type value current length next previous length blur focus onBlur onChange onFocus onReset onSubmit Form reset submit forms array Frame none blur clearTimeout focus setTimeout none onBlur onFocus frames array Hidden none none none none history back forward go none none history array none file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary.htm Image border complete height hspace lowsrc name prototype src vspace width length hash host hostname href pathname port protocol search target length hash host hostname href pathname port protocol search E LN2 LN10 LOG2E LOG10E PI SQRT1_2 SQRT2 none onAbort onError onLoad images array Link and Area none none none onClick onMouseOut onMouseOver links array location none reload replace none none Math abs acos asin atan atan2 ceil cos exp floor log max min none file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary.htm (4 of 7) [30/08/2003 9:34:36 PM] .

htm pow random round sin sqrt tan MimeType description none enabledPlugin type suffixes length none appCodeName javaEnabled appName taintEnabled appVersion mimeTypes plugins userAgent length none none mimeTypes array navigator none none options array none none options array elements defaultSelected none index length selected selectedIndex text value Password defaultValue form name type value description filename length name length blur focus select onBlur onFocus Plugin none none plugins array refresh none file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary.htm (5 of 7) [30/08/2003 9:34:36 PM] .

htm (6 of 7) [30/08/2003 9:34:36 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary.htm Radio checked blur defaultChecked click form focus length name type value form name type value form length name options selectedIndex text type length prototype blur click focus blur focus onBlur onClick onFocus Reset onBlur onClick onFocus onBlur onChange onFocus Select String anchor big blink bold charAt fixed fontcolor fontsize indexOf italics lastIndexOf link small split strike sub substring sup toLowerCase toUpperCase none file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary.htm (7 of 7) [30/08/2003 9:34:36 PM] .htm Submit form name type value defaultValue form name type value defaultValue form name type value closed defaultStatus document Frame frames history length location name opener parent self status top window blur click focus blur focus select onBlur onClick onFocus onBlur onChange onFocus onSelect onBlur onChange onFocus onSelect onBlur onError onFocus onLoad onUnload Text Textarea blur focus select window alert blur clearTimeOut close confirm focus open prompt setTimeOut file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/summary.

or object names. methods. Some of these words are keywords used in JavaScript.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/keywords. functions. others are reserved for future use.htm [30/08/2003 9:34:37 PM] .htm Reserved words he reserved words in this list cannot be used as JavaScript variables. abstract boolean break byte case catch char class const continue default delete do double else extends false final finally float for function goto if implements import in instanceof int interface long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void while with file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/keywords.

and vlinkColor properties and the fontcolor method. fgColor.htm (1 of 5) [30/08/2003 9:34:38 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/colors. bgColor. linkColor. and blue hexadecimal values. you can use the indicated red. green. Color aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate Red Green Blue F0 00 7F F0 F5 FF 00 FF 00 F8 FF FF FF F5 E4 00 EB 00 FF D7 FF D4 FF DC C4 00 CD FF E2 2A 87 A0 00 1E FA EB 8A 2B A5 2A DE B8 5F 7F 9E FF D2 69 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/colors. for example <BODY BGCOLOR="bisque"> or <FONT COLOR="blue">color me blue</font> Instead of using the string to specify a color.htm Color values he string literals in this table can be used to specify colors in the JavaScript alinkColor. You can also use these string literals to set the colors in HTML tags.

htm (2 of 5) [30/08/2003 9:34:38 PM] .htm coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkturquoise darkviolet deeppink deepskyblue dimgray dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite FF 64 FF 00 00 00 7F 95 F8 FF 00 8B 50 ED DC 3C FF 8B 8B 0B A9 00 6B 8B 2F 00 CC 00 7A 8F 8B 4F D1 D3 93 FF 69 FF 22 F0 22 FF DC FF DC 14 B8 86 A9 A9 00 64 BD B7 8B 00 55 FF 99 E9 8F 48 2F 00 94 FF 00 69 1E FF 22 FF F8 6B 8C 32 96 BC 3D 4F CE 00 14 BF 69 90 FA 8B 00 F8 8B 00 B2 22 DC DC file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/colors.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/colors.

htm (3 of 5) [30/08/2003 9:34:38 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/colors.htm gold goldenrod gray green greenyellow honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightsteelblue lightyellow lime limegreen linen magenta FF 80 00 F0 FF D7 80 80 FF 69 00 20 80 00 2F F0 B4 5C 82 F0 8C FA F5 00 CD E6 80 FF D2 90 D3 C1 7A AA FA 99 DE E0 00 32 E6 FF DA A5 AD FF CD 5C 4B 00 FF F0 E6 FF FF F0 E0 90 FF FF 20 87 77 FF 00 32 FF FF E6 E6 F0 FA 80 FF EE B6 A0 B2 CE 88 FF FF CD 00 7C FC AD D8 lightgoldenrodyellow FA FA D3 D3 B0 C4 FA F0 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/colors.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/colors.htm maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue 80 66 00 93 00 CD 00 70 00 AA CD D3 DB 71 EE 9A CC 85 70 FA E1 B5 AD 80 E6 00 23 00 00 D6 AA 98 EE 93 D5 B9 3F CB DD E6 BA 55 3C B3 7B 68 00 48 19 F5 FF FF FF 00 80 FF FF FA D1 19 FF E4 E4 DE 00 80 A5 45 C7 15 FD F5 6B 8E DA 70 EE E8 98 FB AF EE DB 70 FF FF FF EF DA C0 CD 85 DD A0 B0 E0 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/colors.htm (4 of 5) [30/08/2003 9:34:38 PM] .

htm (5 of 5) [30/08/2003 9:34:38 PM] .htm purple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen 80 FF 41 00 00 69 80 00 8F E1 13 72 60 57 EE 2D C0 EB CD 90 FA 7F B4 8C 80 D8 47 D0 EE B3 FF F5 00 32 BC 8F 8B 45 FA 80 F4 2E FF A4 8B F5 A0 52 C0 C0 87 70 FF 00 46 00 FF 40 F5 FF F5 FF CE 80 FA FF 82 80 63 E0 DE FF F5 FF 6A 5A D2 B4 D8 BF EE 82 9A CD file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/colors.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/colors.

DOMAIN=domainName] [. Once the expiration date has been reached. with the LiveWire the client object. Programmatically. Transparently. EXPIRES=dateValue specifies a date string that defines the valid life time of that cookie.htm (1 of 5) [30/08/2003 9:34:38 PM] . it is not a formal specification or standard. This appendix discusses the implementation of cookies in the Navigator client. with client-side JavaScript using the cookie property of the document object. see the LiveWire Developer's Guide. comma and white space. The date string is formatted as: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/cookies. You can manipulate cookies q q q Explicitly. For information about using cookies in LiveWire. and discusses using CGI programs and JavaScript to manipulate cookies. If you do not specify dateValue.htm Netscape cookies cookie is a small piece of information stored on the client machine in the cookies. the cookie will no longer be stored or given out. when using client-cookie maintenance. This appendix describes the format of cookie information in the HTTP header. Syntax A CGI program uses the following syntax to add cookie information to the HTTP header: Set-Cookie: name=value [.txt file. To place restricted characters in the name or value. with a CGI program. the cookie expires when the user's session ends.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/cookies. use an encoding method such as URL-style %XX encoding.PATH=pathName] [.EXPIRES=dateValue] [.SECURE] Parameters name=value is a sequence of characters excluding semi-colon.

com" would match host names "anvil.com" as well as "shipping. all other domains require at least three periods.crate. Any domain in the "COM".com". See "Determining a valid cookie". If you do not specify a value for pathName. For example. and seconds. a domain attribute of "acme. minutes.htm (2 of 5) [30/08/2003 9:34:38 PM] . See "Determining a valid cookie".acme. Jan or Feb).acme. DD is a two-digit representation of the day of the month. then path matching is performed to determine if the cookie should be sent. respectively. If SECURE is not specified. Many different application types can take advantage of cookies. PATH=pathName specifies the path attributes for a valid cookie. and other applications can store individual user preferences on the client machine. If the domain attribute matches the end of the fully qualified domain name of the host. HH:MM:SS are hours. for CGI programming). For example. domain names must use at least two or periods. "ORG". SECURE specifies that the cookie is transmitted only if the communications channel with the host is a secure. the cookie is considered sent over any channel.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/cookies. Any future HTTP requests made by the client which fall in that range will include a transmittal of the current value of the state object from the client back to the server. "NET". DOMAIN=domainName specifies the domain attributes for a valid cookie. YY is the last two digits of the year. In addition. a shopping application can store information about the currently selected items for use in the current session or a future session. "GOV". Navigator uses the path of the document that created the cookie property (or the path of the document described by the HTTP header. Mon or Tues).htm Wdy. DD-Mon-YY HH:MM:SS GMT where Wdy is the day of the week (for example. Navigator uses the host name of the server which generated the cookie response. Determining a valid cookie When searching the cookie list for valid cookies. and "INT" categories requires only two periods. Included in that information is a description of the range of URLs for which it is valid. a comparison of the domain attributes of the cookie is made with the domain name of the host from which the URL is retrieved. "EDU". Only hosts within the specified domain can set a cookie for a domain. Mon is a three-letter abbreviation for the month (for example. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/cookies. "MIL". Description A server sends cookie information to the client in the HTTP header when the server responds to a request. Only HTTPS (HTTP over SSL) servers are currently secure. If you do not specify a value for domainName.

20 cookies per server or domain. For example. all cookies with a more specific path mapping are sent before cookies with less specific path mappings. A cookie with a higher-level PATH value does not override a more specific PATH value. Specifications for the client When sending cookies to a server. a line containing the name/value pairs of all matching cookies is included in the HTTP request in the following format: Cookie: NAME1=OPAQUE_STRING1. and if there is a match. The path "/" is the most general path. it is difficult for scripts other than the originator of a cookie to delete a cookie. the cookie is considered valid and is sent along with the URL request. the browser matches the URL against all existing cookies. NAME2=OPAQUE_STRING2 . Saving a cookie with the same PATH and NAME values as an existing cookie overwrites the existing cookie. If a cookie has already passed domain matching. Saving a cookie with the same PATH value but a different NAME value adds an additional cookie. and an EXPIRES value which is in the past.. then the pathname component of the URL is compared with the path attribute. PATH=/foo matches "/foobar" and "/foo/bar.. Because the PATH and NAME must match exactly. where the name and the OPAQUE_STRING combine to form the 4 kilobyte limit.htm (3 of 5) [30/08/2003 9:34:38 PM] . a cookie "name1=foo" with a path mapping of "/" should be sent after a cookie "name1=foo2" with a path mapping of "/bar" if they are both to be sent.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/cookies. Syntax of the cookie HTTP request header When requesting a URL from an HTTP server. Completely specified hosts and domains are considered separate file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/cookies. A CGI script can delete a cookie by returning a cookie with the same PATH and NAME values. Navigator will also delete a cookie before its expiration date arrives if the number of cookies exceeds its internal limits.htm PATH=pathName specifies the URLs in a domain for which the cookie is valid. all the matching cookies are sent. The Navigator can receive and store the following: q q q 300 total cookies 4 kilobytes per cookie.html". When a cookie matches the URL request. For example. Saving cookies A single server response can issue multiple Set-Cookie headers. as shown in the examples below. If there are multiple matches with separate paths. The EXPIRES value indicates when to purge the mapping.

For an example of using cookies with JavaScript. Examples The following examples illustrate the transaction sequence in typical CGI programs. Navigator deletes the least recently used cookie. When a cookie larger than 4 kilobytes is encountered the cookie should be trimmed to fit.htm (4 of 5) [30/08/2003 9:34:38 PM] .htm entities. and receives in the response: Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001. it sends: Cookie: CUSTOMER=WILE_E_COYOTE. it sends: Cookie: CUSTOMER=WILE_E_COYOTE.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/cookies. Example 1 Client requests a document. PART_NUMBER=ROCKET_LAUNCHER_0001 When client requests a URL in path "/foo" on this server. it sends: Cookie: CUSTOMER=WILE_E_COYOTE Client requests a document. expires=Wednesday. When the 300 cookie limit or the 20 cookie per server limit is exceeded. and receives in the response: Set-Cookie: CUSTOMER=WILE_E_COYOTE. PART_NUMBER=ROCKET_LAUNCHER_0001 Client receives: Set-Cookie: SHIPPING=FEDEX. it sends: file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/cookies. path=/foo When client requests a URL in path "/" on this server. see "cookie". 09-Nov-99 23:12:40 GMT When client requests a URL in path "/" on this server. path=/ When client requests a URL in path "/" on this server. but the name should remain intact as long as it is less than 4 kilobytes. and each has a 20 cookie limitation. path=/.

htm Cookie: CUSTOMER=WILE_E_COYOTE.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/cookies. path=/ When client requests a URL in path "/" on this server. PART_NUMBER=ROCKET_LAUNCHER_0001 There are two name/value pairs named "PART_NUMBER" due to the inheritance of the "/" mapping in addition to the "/ammo" mapping. path=/ammo When client requests a URL in path "/ammo" on this server. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/cookies. it sends: Cookie: PART_NUMBER=RIDING_ROCKET_0023. SHIPPING=FEDEX Example 2 This example assumes all mappings from Example 1 have been cleared. it sends: Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001 Client receives: Set-Cookie: PART_NUMBER=RIDING_ROCKET_0023. PART_NUMBER=ROCKET_LAUNCHER_0001. Client receives: Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001.htm (5 of 5) [30/08/2003 9:34:38 PM] .

LiveAudio.without "%" sign}) fade_to({volume percent you wish to fade to . For these methods to be available to JavaScript (and the web page). FALSE or an INT]}. '{url_to_sound}') pause() stop() StopAll() start_time({number of seconds}) end_time({number of seconds}) setvol({percentage number .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/liveaud. have an object "say" what it does when the users clicks it or moves the mouse over it Essentially.without the "%" sign}) fade_from_to({volume percent start fade}. for example.htm (1 of 4) [30/08/2003 9:34:39 PM] .htm LiveAudio and LiveConnect iveAudio is LiveConnect aware. you can accomplish the following type of things programmatically: q q q q Create alternative sound control interfaces Defer the load of a sound file until the user clicks the "play" button Create buttons that make "clicking" noises Create audio confirmation for interface interactions.) q q q q q q q q q q q play({loop[TRUE. JavaScript methods for controlling LiveAudio LiveAudio provides the following major JavaScript controlling methods. (Note: Expressions placed in "{}" are comments and should not be placed in JavaScript literally. Using LiveConnect. and JavaScript. any event that can be described programmatically using the already rich JavaScript framework can trigger a sound event. it can even be hidden) somewhere on your page. You use JavaScript to control embedded LiveAudio elements. {volume percent end fade}) start_at_beginning() stop_at_end() The following JavaScript state indication methods do not control the LiveAudio plug-in. you must embed a LiveAudio console (any console will do. but they give you information about the current state of the plug-in: q q q q IsReady IsPlaying IsPaused GetVolume file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/liveaud.

and can go a long way towards eliminating confusion. Rather than use the embeds array. If you are using the document. Another common example of using LiveConnect and LiveAudio is to defer loading a sound until a user clicks the "play" button.play(false)"> Play the sound now!</A> </BODY> </HTML> This is a much more descriptive way to describe your plug-in in JavaScript. because the embeds array is a Navigator 3.firstsound. This is because any time a NAME attribute is used referencing LiveAudio. Navigator 2.embeds[0]. but can pose many problems.htm (2 of 4) [30/08/2003 9:34:39 PM] .play(false)"> Play the sound now!</A> </BODY> </HTML> The preceding method of playing a sound file is probably the simplest. as follows: <HTML> <BODY> <EMBED SRC="sound1. In the following example. for example you had several sounds embedded in an HTML document. notice that the MASTERSOUND attribute in the <EMBED> tag is used. In the preceding example.wav" HIDDEN=TRUE NAME="firstsound" MASTERSOUND> <A HREF="javascript:document.Hide JavaScript from older browsers file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/liveaud.0 feature.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/liveaud. an accommodating MASTERSOUND tag must be present as well.wav" HIDDEN=TRUE> <A HREF="javascript:document. <HTML> <BODY> <EMBED SRC="sound1. To do this.htm Using the LiveAudio LiveConnect methods One example of using JavaScript to control a LiveAudio plug-in is to have JavaScript play a sound. you can identify the particular <EMBED> tag you would like to use in JavaScript by using the NAME and MASTERSOUND attributes in your original <EMBED> tag.embeds array. If. all of the HTML is needed to make the plug-in play a sound. try the following: <HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript> <!-. it may be easier for developers to use the NAME attribute rather than the embeds array.0 will generate an error.

firstSound. Web designers might want to create entire new interfaces with LiveConnected LiveAudio. } function stopSound() { document.pause(). a designer might do the following: <HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript> <!-.Hide JavaScript from older browsers function playSound() { document.stop().play(false. stub1. the sound file is loaded only when the user wants to hear it.htm function playDeferredSound() { document.wav" HIDDEN=TRUE NAME="firstsound" MASTERSOUND> <A HREF="javascript:playDeferredSound()">Load and play the sound</A> </BODY> </HTML> The stub file.wav.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/liveaud.firstSound.firstSound. (For a description of how to create a stub file. is loaded relatively quickly.firstSound.play(false). } if ( newVolume < 90 ) { document. } // --> </SCRIPT> </HEAD> <BODY> <EMBED SRC="stub1.GetVolume().GetVolume() == 100 ) { alert("Volume is already at maximum").setvol(newVolume) .firstsound. To create an alternate console for sound playing and interaction. see the EmeraldNet LiveAudio information at http://emerald.) The play method then loads the sound file only when it is called. if ( document. } function pauseSound() { document. } else { file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/liveaud. newVolume = ( currentVolume + 10 ) .firstSound.htm (3 of 4) [30/08/2003 9:34:39 PM] .net/liveaudio/. } function volup() { currentVolume = document. Using this example.wav').firstSound. 'http://url_to_new_sound_file/sound1.

firstSound. file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/liveaud. } else { if ( ( newVolume >= 0 ) && ( newVolume < 10 ) ) { document.htm (4 of 4) [30/08/2003 9:34:39 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/liveaud. The possibilities are really endless. } } } function voldown() { currentVolume = document.htm if ( ( newVolume <= 100 ) && ( newVolume > 90 ) ) { document.wav" HIDDEN=TRUE AUTOSTART=FALSE NAME="firstSound" MASTERSOUND> <P><A HREF="javascript:playSound()">Play the sound now!</A></P> <P><A HREF="javascript:pauseSound()">Pause the sound now!</A></P> <P><A HREF="javascript:stopSound()">Stop the sound now!</A></P> <P><A HREF="javascript:volup()">Increment the Volume!</A></P> <P><A HREF="javascript:voldown()">Decrement the Volume!</A></P> </BODY> </HTML> The preceding example illustrates how you might create your own method of controlling a sound file. } } } // --> </SCRIPT> </HEAD> <BODY> <EMBED SRC="sound1. newVolume = ( currentVolume . if ( document.setvol(0) .setvol(newVolume) .firstSound. } if ( newVolume > 10 ) { document.GetVolume() == 0 ) { alert("Volume is already at minimum").firstSound.firstSound.10 ) .setvol(100) . you can use images and onClick event handlers to simulate your own sound player.GetVolume().firstSound.

htm (1 of 32) [30/08/2003 9:34:43 PM] . 177 alinkColor property 178 anchor method 179 Anchor object 179 See also anchors anchors Anchor object 179 creating 179 defining 179 linking to 66 anchors array 180 anchors property See anchors array animation 288 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 149. 317 abs method 175 absolute value 175 accumulator See tainting acos method 176 ACTION attribute 176.htm JavaScript Guide index Symbols ! operator 112 # (hash mark in URL) 275 % operator 109 & operator 110 && operator 112 */ comment 149. 154 // comment 29. 154 -. 154 ^ operator 110 | operator 110 || operator 112 ~ operator 110 A A HTML tag 66.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 51. 179.operator 109 ++ operator 109 /* comment 149. 305 abort event 336 about: (URL syntax) 316. 252 action property 176 alert method 41.

192 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm (2 of 32) [30/08/2003 9:34:43 PM] . 305 See Link object arguments array 120. 129. 189 arithmetic operators decrement 109 increment 109 modulus 108 unary negation 109 Array object 190 creating 128 overview 127 arrays See also the individual arrays Array object 190 associative 118 creating from strings 419 defined 128 dense 192 increasing length of 191 indexing 55. determining 301 list of predefined 54 null elements 106 populating 128 predefined 54 referring to elements 55. 129. 192 initial length of 191 joining 298 length of.htm appCodeName property 183 APPLET HTML tag 184 Applet object 184 applets controlling with LiveConnect 73 example of 74.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 75 flashing text example 75 Hello World example 74. 80 including in a web page 184 referencing 73 applets array 185 appName property 187 appVersion property 187 arc cosine 176 arc sine 193 arc tangent 194 AREA HTML tag 305 Area object 189.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 453 asin method 193 assignment operators 107 defined 105 atan method 194 atan2 method 194 B Back button 195 back method 195 background color 196 bgColor property 196 BIG HTML tag 196 big method 196 bitwise operators logical 110 overview 110 shift 111 BLINK HTML tag 197 blink method 197 blur event 337 blur method 51.htm (3 of 32) [30/08/2003 9:34:43 PM] . 198 BOLD HTML tag 199 bold method 199 Boolean literals 102 Boolean object 200 overview 130 border property 201 break statement 145.htm reversing 390 sorting 416 transposing 390 undefined elements 106 ASCII. 154 browser about: (URL syntax) 317 code name of 183 hiding scripts from 29 name of 187 navigator object 332 user agent 455 version of 187 Button object 202 See also buttons file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. string value 239.

462 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 211 click event 339 click method 211 client JavaScript 23 close method 51 document object 212 window object 58. 312. 101. 428 C caching graphics 289 call method (LiveConnect) 167 caller property 204 case sensitivity 27.htm (4 of 32) [30/08/2003 9:34:43 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm buttons Button object 202 clicking programmatically 211 defining 202 reset 387 submit 44. 117 ceil method 205 CGI programs and image maps 85 and server JavaScript 24 submitting forms to 44 validating form input for 42 change event 339 charAt method 206 Checkbox object 206 See also checkboxes checkboxes Checkbox object 206 checking programmatically 210 clicking programmatically 211 default selection state 222 defining 206 selection state 210 checked property 210 clearTimeout method 134. 213 closed property 214 colors background 196 font 249 foreground 243 hexadecimal values 487 link 178.

htm list of 487 string literals 487 string literals for 487-492 text 243 commas. 216 constructor property 217 containership specifying default object 148.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm (5 of 32) [30/08/2003 9:34:43 PM] . 162 with statement and 148. 154 comments 29. 154 types of 149 comparison operators 108 complete property 215 compute function 41 conditional expressions 106 conditional statements 141-142 confirm method 41. in cookies 87 comment statement 149. times creating 130 overview 130 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 99 JavaScript to Java conversion 77 Date object 221 See also dates. 155 conventions 153 cookie property 218 cookies 218 defined 86 example of use 89 implementation of 493-497 with JavaScript 88 limitations for 87 cos method 219 cosine 219 current property 220 D data tainting See tainting data types converting 100 and Date object 99 Java to JavaScript conversion 81 in JavaScript 26. 51. 162 continue statement 145.

htm using 130-134 dates See also times converting to string 445 cookie expiration 87 Date object 221 day of month 268 day of week 269 defining 221 GMT conversion 444 milliseconds since 1970 359. 216 Prompt 51. specifying 148. 51. 228 See also documents anchors array 180 applets array 185 described 52 embeds array 235 example of properties 47-49 forms array 253 images array 289 links array 308 documentation conventions 18-19 documents See also windows anchors array 180 anchors in 180 applets array 185 applets in 185 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. conventions used 18 document object 46. 177 Confirm 41.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 415 decrement operator 109 default objects. 162 defaultChecked property 222 defaultSelected property 223 defaultStatus property 86. 225 defaultValue property 226 dense arrays 192 description property 227 destroy method (LiveConnect) 172 dialog boxes Alert 51. 372 directories. 456 month 270 working with 130 year 272.htm (6 of 32) [30/08/2003 9:34:43 PM] .

. 351 opening 351 reloading 383 title 444 writing to 471.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 252 end_time method (LiveAudio) 500 entities 32 error event 341 escape function 87.. 300 links array 308 onUnload event handler 345. 88. 239 escaping characters 103 Euler's constant 233 base 10 logarithm of 319 base 2 logarithm of 319 raised to a power 242 eval function 41. 472 domain property 232 E E property 233 elements array 52.else statement embeds array 235 embeds property See embeds array enabledPlugin property 237 encoding property 238 ENCTYPE attribute 238. 234 elements property See elements array else statement See if. 228 embeds array 235 error handler for 341 forms array 253 images array 289 images in 289 last modified date 257.htm closing 212 color of 196.htm (7 of 32) [30/08/2003 9:34:43 PM] . 243 current URL 454 defining 228 displaying HTML output in 228 document object 52. 100 eval method 240 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.

defined 37 exp method 242 expressions conditional 106 in HTML attributes 32 overview 105 that return no value 115 types of 105 F fade_from_to method (LiveAudio) 500 fade_to method (LiveAudio) 500 fgColor property 243 file: (URL syntax) 316 filename property 244 FileUpload object 244 fixed method 246 flashing text applet example 75 floating-point literals 102 floor method 247 focus giving 247 onBlur event handler 337 onChange event handler 339 onFocus event handler 344 removing 198 focus event 344 focus method 51.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 247 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm (8 of 32) [30/08/2003 9:34:43 PM] .htm eval method (LiveConnect) 168 event handlers 336-351 See also the individual event handlers defining 37 defining functions for 39 example of use 40-41 in Function objects 267 list of 38 quotation marks for 40 referring to windows 64 resetting 41 scripting 37-41 specifying object names in 213 summary of 475-483 syntax for 39 events.

in statement 147. 252 FileUpload objects 244 Form object 52. 155 for. 251 Form object 251 See also forms described 52 elements array 52. 251 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex... 156 foreground color 243 form elements type of 451 updating 37 updating dynamically 50 FORM HTML tag 46. 247 element names 328 elements array 52. 66. 154 for statement 142-143. 234 ENCTYPE attribute 238.htm fontcolor method 249 fonts big 196 blinking 197 bold 199 color of 249 fixed 246 italic 297 size of 250 small 416 strikeout 424 subscript 427 superscript 432 FONTSIZE HTML tag 250 fontsize method 250 for loops continuation of 145.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 234 form property 257 forms ACTION attribute 176.htm (9 of 32) [30/08/2003 9:34:43 PM] . 252 buttons 202 checkboxes 206 defining 251 destination URL 176 element focus 198. 155 sequence of execution 142 syntax of 155 termination of 145.

261 hierarchy of 60 name of. 64-66 top 446 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 253 forms property See forms array Forward button 258 forward method 258 FRAME HTML tag 51. 428 TARGET attribute 251 target property 436 Text objects 436 Textarea objects 440 validating input 42 forms array 52.htm (10 of 32) [30/08/2003 9:34:43 PM] . 61.htm forms array 52.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 253 Hidden object 276 METHOD attribute 252. 259 frames array 60. linking to 66 navigating 62 parent 358 referring to 62. 252 number of elements 301 onSubmit event handler 350 Password objects 362 radio buttons 378 referring to windows in submit 66 reset buttons 387 reset event handler 349 resetting values 387 selection lists 396 submit buttons 428 submitting 427. 66 Frame object 259 See also frames described 51 frames array 261 frames closing 58 creating 59 defined 59 defining 259 example of creation 62-63 figure of 59 Frame object 51. 323 MIME encoding 238.

htm updating 61 frames array 60. 269 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 269 getHours method 133. 261 frames property See frames array FRAMESET HTML tag 59. 118 Function object 265 overview 134 specifying arguments for 266 specifying event handler with 267 as variable value 266 function statement 157 functions 175-473 See also the individual functions arguments array 189 caller property 204 calling 33-35 defined 33 defining 33-35 defining and calling 118-120 escape 239 examples of 43 excess arguments for 120 Function object 134.htm (11 of 32) [30/08/2003 9:34:43 PM] . 265 isNAN 296 isNan 139 number of arguments 301 parseFloat 140. 259 ftp: (URL syntax) 316 function keyword 33. 360 recursive 119 return values of 160 taint 434 unescape 453 untaint 453 using built in 139-140 using validation 44 as variable value 266 G getDate method 268 getDay method 131. 359 parseInt 140.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 61.

372 replacing current entry 351. 273 gopher: (URL syntax) 316 graphics See images H hash property 275 HEAD HTML tag 119 height property 276 Hello World applet example 74. 270 getMonth method 270 getPeer method (LiveConnect) 172 getSeconds method 133. 385 History menu option 273 history object 46.htm getMember method (LiveConnect) 168 getMinutes method 133. 279 go method 53. 80 Hidden object 276 history array 279 history list 53 current URL in 220 loading URL from 273 next URL in 258. 271 getTimezoneOffset method 272 GetVolume method (LiveAudio) 500 getWindow method (LiveConnect) 172 getWindow static method (LiveConnect) 168 getYear method 272 Go menu 273.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm (12 of 32) [30/08/2003 9:34:43 PM] . 334 previous URL in 195. 271 getSlot method (LiveConnect) 168 getTime method 132. 279 current property 220 described 53 history array 279 next property 334 number of entries 301 previous property 372 history property See history array host property 281 hostname property 282 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.

305 APPLET 184 AREA 305 BIG 196 BLINK 197 BOLD 199 FONTSIZE 250 FORM 46. 251 FRAME 51. 472 and JavaScript 17 HTML layout 49-50 HTML tags A 66. 179. 66. 305 NOSCRIPT 33 PRE 36 SCRIPT 27 SELECT 396 SMALL 416 STRIKE 424 SUB 427 SUP 432 TEXTAREA 440 TITLE 48 TT 246 http: (URL syntax) 316 hypertext See links HyperText Markup Language See HTML I I HTML tag 297 identity taint code 92 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 387.htm (13 of 32) [30/08/2003 9:34:43 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 286 INPUT 202. 428. 244. 378. 259 HEAD 119 I 297 IMG 85. 206. 362. 436 MAP 84. 66 FRAMESET 59.htm HREF attribute 85 href property 283 hspace property 285 HTML embedding JavaScript in 27-33 generated 471. 276.

428. 378. 276. 286 increment operator 109 index property 294 indexOf method 295 infinity negative 333 positive 371 init method (LiveConnect) 172 INPUT HTML tag 202..else statement 141.htm (14 of 32) [30/08/2003 9:34:43 PM] . 362. 206. 387.. in JavaScript 102 isActive method (LiveConnect) 173 ISMAP attribute 85 isNaN function 296 isNan function overview 139 IsPaused method (LiveAudio) 500 IsPlaying method (LiveAudio) 500 IsReady method (LiveAudio) 500 italics method 297 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 157 image maps client-side 84 server-side 85 Image object 286 images aborting load of 336 and animation 288 Area object 305 border 201 caching 289 completion of loading 215 error handler for 341 height 276 horizontal space around 285 Image object 286 low resolution source 320 onAbort event handler 336 preloading 289 size of 288 source 421 vertical space around 463 width of 464 images array 289 images property See images array IMG HTML tag 85. 244.htm if.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 436 integers.

317 join method 298 JSException class 169 JSException constructor (LiveConnect) 170 JSObject class 165 K keywords 485 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm J Java See also LiveConnect accessing with LiveConnect 72 communication with JavaScript 69-82 compared to JavaScript 26 determining whether enabled 298 enabling and disabling 298 getting JavaScript window handle 78 to JavaScript communication 77 java package 70 java_30 file 71 javaEnabled method 298 JavaScript background for using 17 case sensitivity 27 communication with Java 69-82 compared to Java 26 described 25 embedding in HTML 27-33 entities 32 external file of 30 and HTML layout 49-50 to Java communication 72 LiveWire 24-25 Navigator 23-24 reserved words 485 right-hand evaluation 32 special characters 103 specifying version 27 types of 23 URLs 83 javascript: (URL syntax) 316.htm (15 of 32) [30/08/2003 9:34:43 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.

305 image maps 85 and images 305 Link object 305 links array 308 referring to windows 66 target 436 with no destination 115 links array 308 links property See links array lists.htm L LANGUAGE attribute 27 language. 462 creating 66 defining 304. 312. HTML 49-50 left shift operator 111 length property 138.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. selection 396 literals Boolean 102 floating point 102 integers 102 overview 101 string 102 LiveAudio 499-504 examples 501 and LiveConnect 499-504 methods 500 LiveConnect 69-82 accessing Java directly 72 accessing JavaScript objects 78 accessing JavaScript properties 78 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm (16 of 32) [30/08/2003 9:34:43 PM] . 301 link method 304 Link object 305 See also links Area objects 307 linkColor property 312 links anchors for 179 and areas 305 color of 178. specifying 27 lastIndexOf method 299 lastModified property 300 layout.

in 147. validating form input for 42 LiveWire JavaScript See server JavaScript LN10 property 313 LN2 property 313 load event 345 location object 46.. 454 log method 318 LOG10E property 319 LOG2E property 319 logarithms base 10 of e 319 base 2 of e 319 base of natural 233.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.. 156 termination of 145. 314 described 53 location property 61.htm calling JavaScript methods 79 controlling Java applets 73 controlling Java plug-ins 76 getting a window handle 78 Hello World example 80 and LiveAudio 499-504 packages 165-173 LiveWire applications. 305 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 154 while 161 lowercase 27. 445 lowsrc property 320 M mailto: (URL syntax) 316 MAP HTML tag 84. 242 natural logarithm of 10 313 natural logarithm of 2 313 natural logarithm of a number 318 logical operators overview 112 short-circuit evaluation 113 loop statements for 142-143 while 144 loops continuation of 145. 101. 155 for 155 for.htm (17 of 32) [30/08/2003 9:34:43 PM] .

324 configured plug-in for 237 description property 227 name of 451 plug-ins supported 366 suffixes of 432 MimeType object 324 mimeTypes array 94. 177 Confirm dialog box 51. 252.htm (18 of 32) [30/08/2003 9:34:43 PM] . 372 status bar 86 METHOD attribute 49.htm Math object 321 overview 136 mathematical constants and functions 321 max method 322 MAX_VALUE property 323 MAYSCRIPT attribute 185 messages Alert dialog box 51.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 216 Prompt dialog box 51. 325 mimeTypes property See mimeTypes array min method 327 MIN_VALUE property 328 modulo function 109 modulus operator 108 mouseout event 348 mouseOver event 348 N NAME attribute 48 name property 328 NaN property 331 natural logarithms base of 233 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 323 method property 323 methods 175-473 See also the individual methods defined 35 defining 124 referring to windows 64 summary of 475-483 MIME encoding 238 MIME types client capability 94.

javascript.htm e 233 e raised to a power 242 of 10 313 of 2 313 of a number 318 Navigator See also Navigator 2.javascript package 71.0 See also Navigator Navigator 3.sun package 71 new operator 113.0.Plugin class 171 netscape.JSException class 169 netscape.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm (19 of 32) [30/08/2003 9:34:43 PM] .plugin package 71 netscape. 324 name of 187 navigator object 332 plug-ins in 367 plug-ins installed on 365 predefined arrays 54 printing output 37 user agent 455 version of 187 Navigator 2.javascript.javascript.0 about: (URL syntax) 317 code name of 183 enabling and disabling Java 298 and JavaScript 23. 77 netscape. 158 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 121. Navigator 3.0 See also Navigator changed functionality 510-512 new functionality 505-510 Navigator JavaScript See client JavaScript navigator object 46. 332 See also Navigator described 54 mimeTypes array 325 plugins array 367 NEGATIVE_INFINITY property 333 Netscape packages See packages netscape.applet package 71 netscape.JSObject class 165 netscape. 24 MIME types in 325 MIME types supported 94.

158 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 247 parsing from strings 140.in 147 new operator 146 this keyword 147 with statement 148 objects 175-473 See also the individual objects adding properties 123. 360 random 382 rounding 391 sine of 415 square root 420. 374 creating new types 121-123.htm news: (URL syntax) 316 next property 334 NOSCRIPT HTML tag 33 NS_ENABLE_TAINT environment variable 91 null keyword 106 Number object 335 overview 137 numbers absolute value of 175 arc cosine of 176 arc sine of 193 arc tangent of 194 base of 447 cosine of 219 defining Number objects 335 exponents of 371 greater of two 322 infinite 333.htm (20 of 32) [30/08/2003 9:34:43 PM] . 335 obtaining integer 205.. 371 isNAN 296 lesser of two 327 maximum value 323 minimum value 328 natural logarithm of 318 not-a-number value 331 Number object 137. 421 tangent of 435 O object manipulation statements for. 359..

339 onClick event handler 41. 339 onError event handler 341 onFocus event handler 344 onLoad event handler 133. 42. 89. 354 opener property 356 operators arithmetic 108-110 assignment 107 bitwise 110-112 comparison 108 defined 105 logical 112 order of 115 overview 106 special 113 string 113 Option object See Select object options array 399 options property See options array output displaying 37 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 350 onUnload event handler 351 open method 51 document object 351 window object 57. 247 hierarchy of 45 indexing properties 123 overview 117 primitive value of 461 prototypes 217 specifying names in event handlers 213 summary of 475-483 onAbort event handler 336 onBlur event handler 337 onChange event handler 42. 162 focus 198. 44.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm deleting 126 establishing default 148. 348 onMouseOver event handler 86. 44.htm (21 of 32) [30/08/2003 9:34:43 PM] . 345 onMouseOut event handler 86. 348 onReset event handler 349 onSelect event handler 350 onSubmit event handler 44.

358 parse method 132. 366 file name of 244 generating output from 235 Plugin object 365 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm (22 of 32) [30/08/2003 9:34:43 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.plugin 71 netscape. 77 netscape. 359 overview 140 parseInt function 100. 360 overview 140 Password object 362 default value 226 pathname property 364 pause method (LiveAudio) 500 PI property 136. 365 play method (LiveAudio) 500 Plugin class 171 Plugin constructor (LiveConnect) 173 Plugin object 365 See also plug-ins plug-ins controlling with LiveConnect 76 defined 366 description property 227 determining installed 94.sun 71 sun 70 using 71 pages objects for 46 updating 37 parent property 64.javascript 71.htm printing 37 output stream closing 212 opening 351 P packages 165-173 java 70 and LiveConnect 70 netscape 70 netscape.applet 71 netscape. 359 parseFloat function 100.

374 indexing 123 naming 49 overview 117 referring to 47 referring to windows 64 summary of 475-483 protocol property 373 prototype property 374 Q quotation marks for string literals 102 using double 40 using single 40 R radio buttons clicking programmatically 211 default selection state 222 defining 378 number of buttons 301 Radio object 378 selecting programmatically 210 selection state 210 Radio object 378 See also radio buttons number of buttons 301 random method 382 referrer property 382 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm refreshing 383 plugins array 95. 372 properties 175-473 See also the individual properties adding to objects 123. 367 plugins property See plugins array port property 370 POSITIVE_INFINITY property 371 pow method 371 PRE HTML tag 36 previous property 372 printing generated HTML 37.htm (23 of 32) [30/08/2003 9:34:43 PM] . 472 prompt method 51.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.

434 untainting 453 scroll method 51.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm (24 of 32) [30/08/2003 9:34:43 PM] .htm reflection 49-50 refresh method 383 reload method 383 removeMember method (LiveConnect) 168 replace method 385 reserved words 485 reset buttons See also buttons clicking programmatically 211 defining 387 reset method 387 Reset object 387 reset event 349 reset method 387 Reset object 387 See also reset buttons return statement 34. 160 reverse method 390 RGB color values 487 right shift operators 112 right-hand evaluation 32 round method 391 S SCRIPT HTML tag 27 LANGUAGE attribute 27 SRC attribute 30 scripts example of 30 hiding 29 SCRIPT tag 27 tainting 90-93. 393 search property 394 security See also tainting closing windows 213 server domain 232 select event 350 SELECT HTML tag 396 select method 395 Select object 396 See also selection lists file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.

413 setvol method (LiveAudio) 500 setYear method 415 sin method 415 sine 415 SMALL HTML tag 416 small method 416 sort method 416 sound file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 412 setTimeOut method 51 setTimeout method 134.htm (25 of 32) [30/08/2003 9:34:43 PM] . 409 semicolons for event handlers 39 in cookies 87 in JavaScript 30 server JavaScript 24 servers accessing 90-93 domain property 232 sharing properties among 232 setDate method 410 setDay method 131 setHours method 410 setMember method (LiveConnect) 168 setMinutes method 411 setMonth method 411 setSeconds method 412 setSlot method (LiveConnect) 169 setTime method 132.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm options array 399 selected property 407 selectedIndex property 408 selection lists adding options 402 changing option text 400 changing selection state 400 default selection state 223 defining 396 deleting options 402 number of options 301 option index 294 option text 439 options array 399 Select object 396 selection state 407 self property 64.

file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex..htm (26 of 32) [30/08/2003 9:34:43 PM] . 453 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 86 setting message 423 status property 52. 423 stop method (LiveAudio) 500 stop_at_end method (LiveAudio) 500 StopAll method (LiveAudio) 500 STRIKE HTML tag 424 strike method 424 string literals 102 String object 424 See also strings overview 137 string operators 113 strings ASCII value of 239. in cookies 87 special operators 113 new 113 typeof 114 void 115 split method 419 sqrt method 420 SQRT1_2 property 420 SQRT2 property 421 square roots 420 of 1/2 420 of 2 421 SRC attribute 30 src property 421 start_at_beginning method (LiveAudio) 500 start_time method (LiveAudio) 500 statements 153-163 See also the individual statements break 145 conditional 141-142 continue 145 for..htm See LiveAudio space characters.in 147 loop 142-146 object manipulation 146-148 overview 141-149 syntax conventions 153 status bar default message 225 displaying hints 86 displaying messages 52. 86.

299 color of 249 converting from date 445 converting to binary 360 converting to floating point 359 creating from arrays 298 defining 424 evaluating 240 fixed font 246 fontsize of 196.htm blinking 197 bold 199 character position within 206. 250.htm (27 of 32) [30/08/2003 9:34:43 PM] . 416 italic 297 length of 301 lowercase 445 splitting into arrays 419 strikeout 424 String object 424 subscript 427 subset of 430 superscript 432 uppercase 451 SUB HTML tag 427 sub method 427 submit buttons See also buttons clicking programmatically 211 defining 428 Submit object 428 submit event 350 submit method 44. 427 Submit object 428 See also submit buttons subscripts 427 substring method 430 subwindows.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 295. updating 37 suffixes property 432 sun package 70 SUP HTML tag 432 sup method 432 superscripts 432 syntax conventions 153 T file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.

htm (28 of 32) [30/08/2003 9:34:43 PM] . 124. 122.form 257 time zones 272 timeouts canceling 211 setting 413 times See also dates Date object 221 defining 221 hours 269 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm taint function 434 taintEnabled method 434 tainting 90-93 accumumlator 93 conditional statements and 93 control flow and 93 domain property 232 enabling 91 individual data elements 92 NS_ENABLE_TAINT 91 overview 90 properties tainted by default 90 taint accumulator 93 taint code 92 taint function 434 taintEnabled method 434 untaint function 453 untainting data elements 92 tan method 435 tangent 435 TARGET attribute 66. 251 target property 436 text color 243 Text object 436 default value 226 defining 436 text property 439 TEXTAREA HTML tag 440 Textarea object 440 default value 226 defining 440 this keyword 39. 160 described 147 for object references 125 this.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 44.

454 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm (29 of 32) [30/08/2003 9:34:43 PM] .file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 446 toString method 447 and arrays 449 and Boolean objects 449 built-in 448 and Functions 450 and Numbers 450 user-defined 448 toString method (LiveConnect) 169 toUpperCase method 451 trigonometric methods acos 176 asin 193 atan 194 cos 219 sin 415 tan 435 TT HTML tag 246 type property 451 typeof operator 114 typographical conventions. 88. 101. 444 toLocaleString method 445 toLowerCase method 445 top property 64. 451 URLs anchor name in 275 calling document's 382 conventions used 19 current 314. 453 unload event 351 untaint function 453 uppercase 27.htm minutes 270 numeric value 271 seconds 271 time zone offset 272 working with 130 TITLE HTML tag 48 title property 444 toGMTString method 87. used in this book 19 U unary negation 109 unescape function 87.

305 link objects 305 Prompt dialog box 372 radio buttons 378 reset buttons 387 selection lists 396 submit buttons 428 Text objects 436 Textarea objects 440 userAgent property 455 UTC method 456 V value property 456 valueOf method 461 values file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 316 url-path 364 user interaction Alert dialog box 177 applets 184 area objects 305 buttons 202 checkboxes 206 Confirm dialog box 216 FileUpload objects 244 image objects 286.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm domain 282 entire URL string 283 examples of common 316 form destination 176 form field input 252 history list 279 host 282 hostname:port 281 IP address 282 javascript: 83 loading from history list 273 next 258 port 370 previous 195 protocol 373 query information 394 replacing 385 syntax of 314.htm (30 of 32) [30/08/2003 9:34:43 PM] .

154 while statement 144. 213 default status message 225 defining 354. 161 width property 464 window object 46.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex.htm (31 of 32) [30/08/2003 9:34:43 PM] . 161 variables declaring 101. 317 void operator 115 vspace property 463 W while loops continuation of 145. 464 See also windows described 51 frames array 261 history array 279 methods of 51 window property 470 windows See also documents closed 214 closing 58. 464 displaying HTML output in 228 frames 259 frames array 261 giving focus to 67 handles for 78 name of 328 naming 58. 161 initializing 161 in JavaScript 101 naming 101 scope of 101 syntax for declaring 161 view-source: (URL syntax) 316 vlinkColor property 462 void function 307. 64 navigating among 67 number of frames 301 file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 155 syntax of 161 termination of 145.htm See data types var statement 101.

htm onLoad event handler 345 onUnload event handler 351 opening 57. 472 See also write method file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 423 taint accumulator 93 title 444 top 446 window object 51. 472 with statement 136.htm (32 of 32) [30/08/2003 9:34:43 PM] . 464 writing to 471.file:///C|/DCPlusPlus/Complete/Hardware%20&%20Software/Javascriptguide/jsindex. 354 overview 57 referring to 64-66 reloading 383 scrolling 393 status bar 225. 162 described 148 write method 52. 472 using 35-37 writeln method 36. 471 example of use 35 generated HTML 471. 52. 119.

Sign up to vote on this title
UsefulNot useful