├── .gitignore ├── es-262 ├── ECMA-262 5.1 edition June 2011.pdf ├── ECMA-262 5th edition December 2009.pdf ├── ECMA-262, 1st edition, June 1997.pdf ├── ECMA-262, 2nd edition, August 1998.pdf └── ECMA-262, 3rd edition, December 1999.pdf ├── js-1.0 ├── alpha.html ├── builtin.html ├── colors.html ├── content.html ├── cookie_spec │ ├── assist_ban.gif │ └── cookie_spec.html ├── events.html ├── expr.html ├── ident.html ├── index.html ├── introd.html ├── keywords.html ├── methods.html ├── model.html ├── navbar.html ├── navobj.html ├── objects.html ├── props.html ├── ref_a-c.html ├── ref_d-e.html ├── ref_f-g.html ├── ref_h-l.html ├── ref_m-q.html ├── ref_r-r.html ├── ref_s-s.html ├── ref_t-z.html ├── script.html ├── stmts.html ├── stmtsov.html ├── toc.html └── winframe.html ├── js-2.0 └── javascript2.0_ evolving_a_language_for_evolving_systems.pdf └── misc └── ES4-language-overview.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /es-262/ECMA-262 5.1 edition June 2011.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwaldron/js-history/b62e5b6c8c80c2d95b47518456f3fb00470122d2/es-262/ECMA-262 5.1 edition June 2011.pdf -------------------------------------------------------------------------------- /es-262/ECMA-262 5th edition December 2009.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwaldron/js-history/b62e5b6c8c80c2d95b47518456f3fb00470122d2/es-262/ECMA-262 5th edition December 2009.pdf -------------------------------------------------------------------------------- /es-262/ECMA-262, 1st edition, June 1997.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwaldron/js-history/b62e5b6c8c80c2d95b47518456f3fb00470122d2/es-262/ECMA-262, 1st edition, June 1997.pdf -------------------------------------------------------------------------------- /es-262/ECMA-262, 2nd edition, August 1998.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwaldron/js-history/b62e5b6c8c80c2d95b47518456f3fb00470122d2/es-262/ECMA-262, 2nd edition, August 1998.pdf -------------------------------------------------------------------------------- /es-262/ECMA-262, 3rd edition, December 1999.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwaldron/js-history/b62e5b6c8c80c2d95b47518456f3fb00470122d2/es-262/ECMA-262, 3rd edition, December 1999.pdf -------------------------------------------------------------------------------- /js-1.0/alpha.html: -------------------------------------------------------------------------------- 1 | 2 | Info Index 3 | 4 | 5 | 6 |

Alphabetical Reference

7 | 8 |
  • abs 9 |
  • acos 10 |
  • action 11 |
  • alert 12 |
  • alinkColor 13 |
  • anchor method 14 |
  • anchor object (anchors array) 15 |
  • anchors property 16 |
  • appCodeName 17 |
  • appName 18 |
  • appVersion 19 |
  • asin 20 |
  • atan 21 |
  • back 22 |
  • bgColor 23 |
  • big 24 |
  • blink 25 |
  • blur 26 |
  • bold 27 |
  • button 28 |
  • ceil 29 |
  • charAt 30 |
  • checkbox 31 |
  • checked 32 |
  • clear 33 |
  • clearTimeout 34 |
  • click 35 |
  • close (document) 36 |
  • close (window) 37 |
  • confirm 38 |
  • cookie 39 |
  • cos 40 |
  • Date 41 |
  • defaultChecked 42 |
  • defaultSelected 43 |
  • defaultStatus 44 |
  • defaultValue 45 |
  • document 46 |
  • E 47 |
  • elements array 48 |
  • elements property 49 |
  • encoding 50 |
  • escape 51 |
  • eval 52 |
  • exp 53 |
  • fgColor 54 |
  • fixed 55 |
  • floor 56 |
  • focus 57 |
  • fontcolor 58 |
  • fontsize 59 |
  • form object (forms array) 60 |
  • forms property 61 |
  • forward 62 |
  • frame object (frames array) 63 |
  • frames property 64 |
  • getDate 65 |
  • getDay 66 |
  • getHours 67 |
  • getMinutes 68 |
  • getMonth 69 |
  • getSeconds 70 |
  • getTime 71 |
  • getTimezoneOffset 72 |
  • getYear 73 |
  • go 74 |
  • hash 75 |
  • hidden 76 |
  • history 77 |
  • host 78 |
  • hostname 79 |
  • href 80 |
  • index 81 |
  • indexOf 82 |
  • isNaN 83 |
  • italics 84 |
  • lastIndexOf 85 |
  • lastModified 86 |
  • length 87 |
  • link method 88 |
  • link object (links array) 89 |
  • linkColor 90 |
  • links property 91 |
  • LN2 92 |
  • LN10 93 |
  • location object 94 |
  • location property 95 |
  • log 96 |
  • LOG2E 97 |
  • LOG10E 98 |
  • Math 99 |
  • max 100 |
  • method 101 |
  • min 102 |
  • name 103 |
  • navigator 104 |
  • onBlur 105 |
  • onChange 106 |
  • onClick 107 |
  • onFocus 108 |
  • onLoad 109 |
  • onMouseOver 110 |
  • onSelect 111 |
  • onSubmit 112 |
  • onUnload 113 |
  • open (document) 114 |
  • open (window) 115 |
  • options 116 |
  • parent 117 |
  • parse 118 |
  • parseFloat 119 |
  • parseInt 120 |
  • password 121 |
  • pathname 122 |
  • PI 123 |
  • port 124 |
  • pow 125 |
  • prompt 126 |
  • protocol 127 |
  • radio 128 |
  • random 129 |
  • referrer 130 |
  • reset 131 |
  • round 132 |
  • search 133 |
  • select method 134 |
  • select object (options array) 135 |
  • selected 136 |
  • selectedIndex 137 |
  • self 138 |
  • setDate 139 |
  • setHours 140 |
  • setMinutes 141 |
  • setMonth 142 |
  • setSeconds 143 |
  • setTime 144 |
  • setTimeout 145 |
  • setYear 146 |
  • sin 147 |
  • small 148 |
  • sqrt 149 |
  • SQRT1_2 150 |
  • SQRT2 151 |
  • status 152 |
  • strike 153 |
  • string 154 |
  • sub 155 |
  • submit method 156 |
  • submit object 157 |
  • substring 158 |
  • sup 159 |
  • tan 160 |
  • target 161 |
  • text object 162 |
  • text property 163 |
  • textarea 164 |
  • title 165 |
  • toGMTString 166 |
  • toLocaleString 167 |
  • toLowerCase 168 |
  • top 169 |
  • toUpperCase 170 |
  • unescape 171 |
  • userAgent 172 |
  • UTC 173 |
  • value 174 |
  • vlinkColor 175 |
  • window object 176 |
  • window property 177 |
  • write 178 |
  • writeln -------------------------------------------------------------------------------- /js-1.0/builtin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

    Using Built-in Objects and Functions

    5 |

    6 | The JavaScript Language contains the following built-in objects and functions: 7 |

    13 |

    14 | These objects and their properties and methods are built into the language. 15 | You can use these objects in both client applications with Netscape Navigator 16 | and server applications with LiveWire. 17 | 18 |

    Using the String Object

    19 |

    20 | Whenever you assign a string value to a variable or property, you create a string object. 21 | String literals are also string objects. For example, the statement 22 |

     23 | mystring = "Hello, World!"
     24 | 
    25 |

    26 | creates a string object called mystring. The literal "blah" is also a string object. 27 | 28 |

    29 | The string object has methods that return: 30 |

    34 |

    35 | For example, given the above object, mystring.toUpperCase() returns "HELLO, WORLD!", 36 | and so does "hello, world!".toUpperCase(). 37 | 38 | 39 |

    Using the Math Object

    40 |

    41 | The built-in Math object has properties and methods for mathematical constants and 42 | functions. For example, the Math object's PI property has the value of pi, which you 43 | would use in an application as 44 |

     45 | Math.PI
     46 | 
    47 |

    48 | Similarly, standard mathematical functions are methods of Math. 49 | These include trigonometric, logarithmic, exponential, and other functions. 50 | For example, if you want to use the trigonometric function sine, you would write 51 |

     52 | Math.sin(1.56)
     53 | 
    54 |

    55 | Note that all trigonometric methods of math take arguments in radians. 56 |

    57 | It is often convenient to use the with statement when a section of code uses several math 58 | constants and methods, so you don't have to type "Math" repeatedly. For example, 59 |

     60 | with (Math) {
     61 |    a = PI * r*r;
     62 |    y = r*sin(theta)
     63 |    x = r*cos(theta)
     64 | }
     65 | 
    66 | 67 |

    Using the Date Object

    68 |

    69 | JavaScript does not have a date data type. However, the date object and its 70 | methods enable you to work with dates and times in your applications. 71 | The date object has a large number of methods for setting, getting, 72 | and manipulating dates. It does not have any properties. 73 |

    74 | JavaScript handles dates very similarly to Java. 75 | The two languages have many of the same date methods, and both languages 76 | store dates as the number of milliseconds since January 1, 1970 00:00:00. 77 |

    78 | NOTE: 79 | You cannot currently work with dates prior to 1/1/70. 80 | 81 |

    To create a date object: 82 |

     83 | varName = new Date(parameters)
     84 | 
    85 | where varName is a JavaScript variable name for the date object being created; 86 | it can be a new object or a property of an existing object. 87 |

    88 | The parameters for the Date constructor can be any of the following: 89 |

    110 |

    111 | The Date object has a large number of methods for handling dates and times. 112 | The methods fall into these broad categories: 113 |

    119 |

    120 | The "get" and "set" methods enable you to get and set seconds, minutes, hours, 121 | day of the month, day of the week, months, and years separately. 122 | There is a getDay method that returns the day of the week, but no 123 | corresponding setDay method, because the day of the week is set automatically. 124 | These methods use integers to represent these values as follows: 125 |

    133 |

    134 | For example, suppose you define the following date: 135 |

    136 | Xmas95 = new Date("December 25, 1995")
    137 | 
    138 | Then Xmas95.getMonth() returns 11, and Xmas95.getYear() 139 | returns 95. 140 |

    141 | The getTime and setTime methods are useful for comparing dates. 142 | The getTime method returns the number of milliseconds since the epoch for 143 | a date object. 144 |

    145 | For example, the following code displays the number of shopping days left until 146 | Christmas: 147 |

    148 | today = new Date()
    149 | nextXmas = new Date("December 25, 1990")
    150 | nextXmas.setYear(today.getYear())
    151 | msPerDay = 24 * 60 * 60 * 1000 ; // Number of milliseconds per day
    152 | daysLeft = (nextXmas.getTime() - today.getTime()) / msPerDay;
    153 | daysLeft = Math.round(daysLeft);
    154 | document.write("Number of Shopping Days until Christmas: " + daysLeft);
    155 | 
    156 |

    157 | This example creates a date object named today that contains today's date. 158 | It then creates a date object named nextXmas, and sets the year to the 159 | current year. Then, using the number of milliseconds per day, it computes 160 | the number of days between today and nextXmas, using getTime, and rounding 161 | to a whole number of days. 162 |

    163 | The parse method is useful for assigning values from date strings to existing 164 | date objects. For example, the following code uses parse and setTime to 165 | assign a date to the IPOdate object. 166 |

    167 | IPOdate = new Date()
    168 | IPOdate.setTime(Date.parse("Aug 9, 1995"))
    169 | 
    170 | 171 | 180 | 181 |

    Using Built-in functions

    182 | 183 |

    184 | JavaScript has several "top-level" functions built-in to the language. 185 | They are: 186 |

    191 | 192 |

    The eval Function

    193 |

    194 | The built-in function eval takes a string as its argument. 195 | The string can be is any string representing a JavaScript expression, statement, 196 | or sequence of statements. 197 | The expression can include variables and properties of existing objects. 198 |

    199 | If the argument represents an expression, eval evaluates the expression. 200 | If the argument represents one or more JavaScript statements, eval performs the statements. 201 | 202 |

    203 | This function is useful for evaluating a string representing an arithmetic expression. 204 | For example, input from a form element is always a string, but you often want to convert 205 | it to a numerical value. 206 |

    207 | The following example takes input in a text field, applies the eval function and displays 208 | the result in another text field. 209 | If you type a numerical expression in the first field, and click on the button, the 210 | expression will be evaluted. For example, enter "(666 * 777) / 3", and click on the button 211 | to see the result. 212 | 213 |

    214 | <SCRIPT> 215 | function compute(obj) { 216 | obj.result.value = eval(obj.expr.value) 217 | } 218 | </SCRIPT> 219 | <FORM NAME="evalform"> 220 | Enter an expression: <INPUT TYPE=text NAME="expr" SIZE=20 > 221 | <BR> 222 | Result: <INPUT TYPE=text NAME="result" SIZE=20 > 223 | <BR> 224 | <INPUT TYPE="button" VALUE="Click Me" onClick="compute(this.form)"> 225 | </FORM> 226 | 227 |

    228 | 229 | 234 |

    235 | Enter an expression: 236 |
    237 | Result: 238 |
    239 | 240 |
    241 | 242 |

    243 | The eval function is not limited to evaluating numerical expressions, however. 244 | Its argument can include object references or even JavaScript statements. 245 | For example, you could define a function called setValue that would take two arguments: 246 | and object and a value, as follows: 247 | 248 |

    249 |  function setValue (myobj, myvalue) {
    250 |    eval ("document.forms[0]." + myobj + ".value") = myvalue;
    251 |  }
    252 | 
    253 | 254 |

    255 | Then, for example, you could call this function to set the value of a form element 256 | "text1" as follows: 257 |

    258 | setValue(text1, 42)
    259 | 
    260 | 261 | 262 |

    The parseInt and parseFloat Functions

    263 | 264 |

    265 | These two built-in functions return a numeric value when given a string as an argument. 266 |

    267 | ParseFloat parses its argument, a string, and attempts to return a floating point number. If it encounters 268 | a character other than a sign ( + or -), numeral (0-9), a decimal point, or an exponent, then it returns 269 | the value up to that point and ignores that character and all succeeding characters. If the first character 270 | cannot be converted to a number, it returns NaN (not a number). 271 |

    272 | The parseInt function parses its first argument, a string, and attempts to return an integer of the 273 | specified radix (base). For example, a radix of 10 indicates to convert to a decimal number, 8 octal, 274 | 16 hexadecimal, and so on. For radixes above 10, the letters of the alphabet indicate numerals greater 275 | than 9. For example, for hexadecimal numbers (base 16), A through F are used. 276 |

    277 | If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all 278 | succeeding characters and returns the integer value parsed up to that point. If the first character cannot 279 | be converted to a number in the specified radix, it returns NaN. ParseInt truncates numbers to integer 280 | values. 281 | 282 | 283 | -------------------------------------------------------------------------------- /js-1.0/colors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

    5 |

    Color values

    6 | 7 |

    The string literals in this table can be used to specify colors in the JavaScript alinkColor, bgColor, fgColor, linkColor, and vlinkColor properties and the fontcolor method. 8 | 9 |

    You can also use these string literals to set the color in the HTML reflections of these properties, for example <BODY BGCOLOR="bisque">, and to set the COLOR attribute of the FONT tag, for example, <FONT COLOR="blue">color</font>. 10 | 11 |

    The following red, green, and blue values are in hexadecimal. 12 | 13 |

    14 | 15 | 16 | 159 | 302 | 445 | 588 | 589 |
    17 | Color 18 |
    aliceblue 19 |
    antiquewhite 20 |
    aqua 21 |
    aquamarine 22 |
    azure 23 |
    beige 24 |
    bisque 25 |
    black 26 |
    blanchedalmond 27 |
    blue 28 |
    blueviolet 29 |
    brown 30 |
    burlywood 31 |
    cadetblue 32 |
    chartreuse 33 |
    chocolate 34 |
    coral 35 |
    cornflowerblue 36 |
    cornsilk 37 |
    crimson 38 |
    cyan 39 |
    darkblue 40 |
    darkcyan 41 |
    darkgoldenrod 42 |
    darkgray 43 |
    darkgreen 44 |
    darkkhaki 45 |
    darkmagenta 46 |
    darkolivegreen 47 |
    darkorange 48 |
    darkorchid 49 |
    darkred 50 |
    darksalmon 51 |
    darkseagreen 52 |
    darkslateblue 53 |
    darkslategray 54 |
    darkturquoise 55 |
    darkviolet 56 |
    deeppink 57 |
    deepskyblue 58 |
    dimgray 59 |
    dodgerblue 60 |
    firebrick 61 |
    floralwhite 62 |
    forestgreen 63 |
    fuchsia 64 |
    gainsboro 65 |
    ghostwhite 66 |
    gold 67 |
    goldenrod 68 |
    gray 69 |
    green 70 |
    greenyellow 71 |
    honeydew 72 |
    hotpink 73 |
    indianred 74 |
    indigo 75 |
    ivory 76 |
    khaki 77 |
    lavender 78 |
    lavenderblush 79 |
    lawngreen 80 |
    lemonchiffon 81 |
    lightblue 82 |
    lightcoral 83 |
    lightcyan 84 |
    lightgoldenrodyellow 85 |
    lightgreen 86 |
    lightgrey 87 |
    lightpink 88 |
    lightsalmon 89 |
    lightseagreen 90 |
    lightskyblue 91 |
    lightslategray 92 |
    lightsteelblue 93 |
    lightyellow 94 |
    lime 95 |
    limegreen 96 |
    linen 97 |
    magenta 98 |
    maroon 99 |
    mediumaquamarine 100 |
    mediumblue 101 |
    mediumorchid 102 |
    mediumpurple 103 |
    mediumseagreen 104 |
    mediumslateblue 105 |
    mediumspringgreen 106 |
    mediumturquoise 107 |
    mediumvioletred 108 |
    midnightblue 109 |
    mintcream 110 |
    mistyrose 111 |
    moccasin 112 |
    navajowhite 113 |
    navy 114 |
    oldlace 115 |
    olive 116 |
    olivedrab 117 |
    orange 118 |
    orangered 119 |
    orchid 120 |
    palegoldenrod 121 |
    palegreen 122 |
    paleturquoise 123 |
    palevioletred 124 |
    papayawhip 125 |
    peachpuff 126 |
    peru 127 |
    pink 128 |
    plum 129 |
    powderblue 130 |
    purple 131 |
    red 132 |
    rosybrown 133 |
    royalblue 134 |
    saddlebrown 135 |
    salmon 136 |
    sandybrown 137 |
    seagreen 138 |
    seashell 139 |
    sienna 140 |
    silver 141 |
    skyblue 142 |
    slateblue 143 |
    slategray 144 |
    snow 145 |
    springgreen 146 |
    steelblue 147 |
    tan 148 |
    teal 149 |
    thistle 150 |
    tomato 151 |
    turquoise 152 |
    violet 153 |
    wheat 154 |
    white 155 |
    whitesmoke 156 |
    yellow 157 |
    yellowgreen 158 |
    160 | Red 161 |
    F0 162 |
    FA 163 |
    00 164 |
    7F 165 |
    F0 166 |
    F5 167 |
    FF 168 |
    00 169 |
    FF 170 |
    00 171 |
    8A 172 |
    A5 173 |
    DE 174 |
    5F 175 |
    7F 176 |
    D2 177 |
    FF 178 |
    64 179 |
    FF 180 |
    DC 181 |
    00 182 |
    00 183 |
    00 184 |
    B8 185 |
    A9 186 |
    00 187 |
    BD 188 |
    8B 189 |
    55 190 |
    FF 191 |
    99 192 |
    8B 193 |
    E9 194 |
    8F 195 |
    48 196 |
    2F 197 |
    00 198 |
    94 199 |
    FF 200 |
    00 201 |
    69 202 |
    1E 203 |
    B2 204 |
    FF 205 |
    22 206 |
    FF 207 |
    DC 208 |
    F8 209 |
    FF 210 |
    DA 211 |
    80 212 |
    00 213 |
    AD 214 |
    F0 215 |
    FF 216 |
    CD 217 |
    4B 218 |
    FF 219 |
    F0 220 |
    E6 221 |
    FF 222 |
    7C 223 |
    FF 224 |
    AD 225 |
    F0 226 |
    E0 227 |
    FA 228 |
    90 229 |
    D3 230 |
    FF 231 |
    FF 232 |
    20 233 |
    87 234 |
    77 235 |
    B0 236 |
    FF 237 |
    00 238 |
    32 239 |
    FA 240 |
    FF 241 |
    80 242 |
    66 243 |
    00 244 |
    BA 245 |
    93 246 |
    3C 247 |
    7B 248 |
    00 249 |
    48 250 |
    C7 251 |
    19 252 |
    F5 253 |
    FF 254 |
    FF 255 |
    FF 256 |
    00 257 |
    FD 258 |
    80 259 |
    6B 260 |
    FF 261 |
    FF 262 |
    DA 263 |
    EE 264 |
    98 265 |
    AF 266 |
    DB 267 |
    FF 268 |
    FF 269 |
    CD 270 |
    FF 271 |
    DD 272 |
    B0 273 |
    80 274 |
    FF 275 |
    BC 276 |
    41 277 |
    8B 278 |
    FA 279 |
    F4 280 |
    2E 281 |
    FF 282 |
    A0 283 |
    C0 284 |
    87 285 |
    6A 286 |
    70 287 |
    FF 288 |
    00 289 |
    46 290 |
    D2 291 |
    00 292 |
    D8 293 |
    FF 294 |
    40 295 |
    EE 296 |
    F5 297 |
    FF 298 |
    F5 299 |
    FF 300 |
    9A 301 |
    303 | Green 304 |
    F8 305 |
    EB 306 |
    FF 307 |
    FF 308 |
    FF 309 |
    F5 310 |
    E4 311 |
    00 312 |
    EB 313 |
    00 314 |
    2B 315 |
    2A 316 |
    B8 317 |
    9E 318 |
    FF 319 |
    69 320 |
    7F 321 |
    95 322 |
    F8 323 |
    14 324 |
    FF 325 |
    00 326 |
    8B 327 |
    86 328 |
    A9 329 |
    64 330 |
    B7 331 |
    00 332 |
    6B 333 |
    8C 334 |
    32 335 |
    00 336 |
    96 337 |
    BC 338 |
    3D 339 |
    4F 340 |
    CE 341 |
    00 342 |
    14 343 |
    BF 344 |
    69 345 |
    90 346 |
    22 347 |
    FA 348 |
    8B 349 |
    00 350 |
    DC 351 |
    F8 352 |
    D7 353 |
    A5 354 |
    80 355 |
    80 356 |
    FF 357 |
    FF 358 |
    69 359 |
    5C 360 |
    00 361 |
    FF 362 |
    E6 363 |
    E6 364 |
    F0 365 |
    FC 366 |
    FA 367 |
    D8 368 |
    80 369 |
    FF 370 |
    FA 371 |
    EE 372 |
    D3 373 |
    B6 374 |
    A0 375 |
    B2 376 |
    CE 377 |
    88 378 |
    C4 379 |
    FF 380 |
    FF 381 |
    CD 382 |
    F0 383 |
    00 384 |
    00 385 |
    CD 386 |
    00 387 |
    55 388 |
    70 389 |
    B3 390 |
    68 391 |
    FA 392 |
    D1 393 |
    15 394 |
    19 395 |
    FF 396 |
    E4 397 |
    E4 398 |
    DE 399 |
    00 400 |
    F5 401 |
    80 402 |
    8E 403 |
    A5 404 |
    45 405 |
    70 406 |
    E8 407 |
    FB 408 |
    EE 409 |
    70 410 |
    EF 411 |
    DA 412 |
    85 413 |
    C0 414 |
    A0 415 |
    E0 416 |
    00 417 |
    00 418 |
    8F 419 |
    69 420 |
    45 421 |
    80 422 |
    A4 423 |
    8B 424 |
    F5 425 |
    52 426 |
    C0 427 |
    CE 428 |
    5A 429 |
    80 430 |
    FA 431 |
    FF 432 |
    82 433 |
    B4 434 |
    80 435 |
    BF 436 |
    63 437 |
    E0 438 |
    82 439 |
    DE 440 |
    FF 441 |
    F5 442 |
    FF 443 |
    CD 444 |
    446 | Blue 447 |
    FF 448 |
    D7 449 |
    FF 450 |
    D4 451 |
    FF 452 |
    DC 453 |
    C4 454 |
    00 455 |
    CD 456 |
    FF 457 |
    E2 458 |
    2A 459 |
    87 460 |
    A0 461 |
    00 462 |
    1E 463 |
    50 464 |
    ED 465 |
    DC 466 |
    3C 467 |
    FF 468 |
    8B 469 |
    8B 470 |
    0B 471 |
    A9 472 |
    00 473 |
    6B 474 |
    8B 475 |
    2F 476 |
    00 477 |
    CC 478 |
    00 479 |
    7A 480 |
    8F 481 |
    8B 482 |
    4F 483 |
    D1 484 |
    D3 485 |
    93 486 |
    FF 487 |
    69 488 |
    FF 489 |
    22 490 |
    F0 491 |
    22 492 |
    FF 493 |
    DC 494 |
    FF 495 |
    00 496 |
    20 497 |
    80 498 |
    00 499 |
    2F 500 |
    F0 501 |
    B4 502 |
    5C 503 |
    82 504 |
    F0 505 |
    8C 506 |
    FA 507 |
    F5 508 |
    00 509 |
    CD 510 |
    E6 511 |
    80 512 |
    FF 513 |
    D2 514 |
    90 515 |
    D3 516 |
    C1 517 |
    7A 518 |
    AA 519 |
    FA 520 |
    99 521 |
    DE 522 |
    E0 523 |
    00 524 |
    32 525 |
    E6 526 |
    FF 527 |
    00 528 |
    AA 529 |
    CD 530 |
    D3 531 |
    DB 532 |
    71 533 |
    EE 534 |
    9A 535 |
    CC 536 |
    85 537 |
    70 538 |
    FA 539 |
    E1 540 |
    B5 541 |
    AD 542 |
    80 543 |
    E6 544 |
    00 545 |
    23 546 |
    00 547 |
    00 548 |
    D6 549 |
    AA 550 |
    98 551 |
    EE 552 |
    93 553 |
    D5 554 |
    B9 555 |
    3F 556 |
    CB 557 |
    DD 558 |
    E6 559 |
    80 560 |
    00 561 |
    8F 562 |
    E1 563 |
    13 564 |
    72 565 |
    60 566 |
    57 567 |
    EE 568 |
    2D 569 |
    C0 570 |
    EB 571 |
    CD 572 |
    90 573 |
    FA 574 |
    7F 575 |
    B4 576 |
    8C 577 |
    80 578 |
    D8 579 |
    47 580 |
    D0 581 |
    EE 582 |
    B3 583 |
    FF 584 |
    F5 585 |
    00 586 |
    32 587 |
    590 | 591 | 592 | 593 |


    594 | 597 | 598 | -------------------------------------------------------------------------------- /js-1.0/content.html: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | -------------------------------------------------------------------------------- /js-1.0/cookie_spec/assist_ban.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwaldron/js-history/b62e5b6c8c80c2d95b47518456f3fb00470122d2/js-1.0/cookie_spec/assist_ban.gif -------------------------------------------------------------------------------- /js-1.0/cookie_spec/cookie_spec.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Client Side State - HTTP Cookies 4 | 5 | 6 | 7 | 8 |
    9 | 10 | 11 | 12 |

    13 | PERSISTENT 14 | CLIENT 15 | STATE
    16 | HTTP COOKIES 17 |

    18 | 19 |

    Preliminary Specification - Use with caution

    20 |
    21 | 22 |
    23 | 24 |
    25 |

    26 | INTRODUCTION 27 |

    28 |
    29 | 30 | Cookies are a general mechanism which server side connections (such as 31 | CGI scripts) can use to both store and retrieve information on the 32 | client side of the connection. The addition of a simple, persistent, 33 | client-side state significantly extends the capabilities of Web-based 34 | client/server applications.

    35 | 36 |

    37 |

    38 | OVERVIEW 39 |

    40 |
    41 | 42 | A server, when returning an HTTP object to a client, may also send a 43 | piece of state information which the client will store. Included in that 44 | state object is a description of the range of URLs for which that state is 45 | valid. Any future HTTP requests made by the client which fall in that 46 | range will include a transmittal of the current value of the state 47 | object from the client back to the server. The state object is called 48 | a cookie, for no compelling reason.

    49 | This simple mechanism provides a powerful new tool which enables a host 50 | of new types of applications to be written for web-based environments. 51 | Shopping applications can now store information about the currently 52 | selected items, for fee services can send back registration information 53 | and free the client from retyping a user-id on next connection, 54 | sites can store per-user preferences on the client, and have the client supply 55 | those preferences every time that site is connected to. 56 | 57 |

    58 |

    59 | SPECIFICATION 60 |

    61 |
    62 | 63 | A cookie is introduced to the client by including a Set-Cookie 64 | header as part of an HTTP response, typically this will be generated 65 | by a CGI script. 66 | 67 |

    Syntax of the Set-Cookie HTTP Response Header

    68 | 69 | This is the format a CGI script would use to add to the HTTP headers 70 | a new piece of data which is to be stored by the client for later retrieval. 71 | 72 |
     73 | Set-Cookie: NAME=VALUE; expires=DATE;
     74 | path=PATH; domain=DOMAIN_NAME; secure
     75 | 
    76 |
    77 |
    NAME=VALUE
    78 | This string is a sequence of characters excluding semi-colon, comma and white 79 | space. If there is a need to place such data in the name or value, some 80 | encoding method such as URL style %XX encoding is recommended, though no 81 | encoding is defined or required.

    This is the only required attribute 82 | on the Set-Cookie header.

    83 |

    expires=DATE 84 |
    85 | The expires attribute specifies a date string that 86 | defines the valid life time of that cookie. Once the expiration 87 | date has been reached, the cookie will no longer be stored or 88 | given out.

    89 | The date string is formatted as: 90 |

    Wdy, DD-Mon-YYYY HH:MM:SS GMT
    91 | This is based on 92 | RFC 822, 93 | RFC 850, 94 | 95 | RFC 1036, and 96 | 97 | RFC 1123, 98 | with the variations that the only legal time zone is GMT and 99 | the separators between the elements of the date must be dashes. 100 |

    101 | expires is an optional attribute. If not specified, the cookie will 102 | expire when the user's session ends.

    103 | Note: There is a bug in Netscape Navigator version 1.1 and earlier. 104 | Only cookies whose path attribute is set explicitly to "/" will 105 | be properly saved between sessions if they have an expires 106 | attribute.

    107 | 108 |

    domain=DOMAIN_NAME 109 |
    110 | When searching the cookie list for valid cookies, a comparison of the 111 | domain 112 | attributes of the cookie is made with the Internet domain name of the 113 | host from which the URL will be fetched. If there is a tail match, 114 | then the cookie will go through path matching to see if it 115 | should be sent. "Tail matching" means that domain attribute 116 | is matched against the tail of the fully qualified domain name of 117 | the host. A domain attribute of "acme.com" would match 118 | host names "anvil.acme.com" as well as "shipping.crate.acme.com".

    119 | 120 | Only hosts within the specified domain 121 | can set a cookie for a domain and domains must have at least two (2) 122 | or three (3) periods in them to prevent domains of the form: 123 | ".com", ".edu", and "va.us". Any domain that fails within 124 | one of the seven special top level domains listed below only require 125 | two periods. Any other domain requires at least three. The 126 | seven special top level domains are: "COM", "EDU", "NET", "ORG", 127 | "GOV", "MIL", and "INT". 128 | 129 |

    130 | The default value of domain is the host name of the server 131 | which generated the cookie response.

    132 |

    path=PATH 133 |
    134 | The path attribute is used to specify the subset of URLs in a 135 | domain for 136 | which the cookie is valid. If a cookie has already passed domain 137 | matching, then the pathname component 138 | of the URL is compared with the path attribute, and if there is 139 | a match, the cookie is considered valid and is sent along with 140 | the URL request. The path "/foo" 141 | would match "/foobar" and "/foo/bar.html". The path "/" is the most 142 | general path.

    143 | If the path is not specified, it as assumed to be the same path 144 | as the document being described by the header which contains the cookie. 145 |

    146 |

    secure 147 |
    148 | If a cookie is marked secure, it will only be transmitted if the 149 | communications channel with the host is a secure one. Currently 150 | this means that secure cookies will only be sent to HTTPS (HTTP over SSL) 151 | servers.

    152 | If secure is not specified, a cookie is considered safe to be sent 153 | in the clear over unsecured channels. 154 |

    155 | 156 |

    Syntax of the Cookie HTTP Request Header

    157 | 158 | When requesting a URL from an HTTP server, the browser will match 159 | the URL against all cookies and if any of them match, a line 160 | containing the name/value pairs of all matching cookies will 161 | be included in the HTTP request. Here is the format of that line: 162 |
    163 | Cookie: NAME1=OPAQUE_STRING1; NAME2=OPAQUE_STRING2 ...
    164 | 
    165 | 166 |

    Additional Notes

    167 | 168 | 229 | 230 |
    231 |

    232 | EXAMPLES 233 |

    234 |
    235 | 236 | Here are some sample exchanges which are designed to illustrate the use 237 | of cookies. 238 |

    First Example transaction sequence:

    239 |
    240 |
    Client requests a document, and receives in the response:
    241 |
    242 | Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT
    243 |
    When client requests a URL in path "/" on this server, it sends:
    244 |
    Cookie: CUSTOMER=WILE_E_COYOTE
    245 |
    Client requests a document, and receives in the response:
    246 |
    Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/
    247 |
    When client requests a URL in path "/" on this server, it sends:
    248 |
    Cookie: CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001
    249 |
    Client receives:
    250 |
    Set-Cookie: SHIPPING=FEDEX; path=/foo
    251 |
    When client requests a URL in path "/" on this server, it sends:
    252 |
    Cookie: CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001
    253 |
    When client requests a URL in path "/foo" on this server, it sends:
    254 |
    Cookie: CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001; SHIPPING=FEDEX
    255 |
    256 |

    Second Example transaction sequence:

    257 |
    258 |
    Assume all mappings from above have been cleared.

    259 |

    Client receives:
    260 |
    Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/
    261 |
    When client requests a URL in path "/" on this server, it sends:
    262 |
    Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001
    263 |
    Client receives:
    264 |
    Set-Cookie: PART_NUMBER=RIDING_ROCKET_0023; path=/ammo
    265 |
    When client requests a URL in path "/ammo" on this server, it sends:
    266 |
    Cookie: PART_NUMBER=RIDING_ROCKET_0023; PART_NUMBER=ROCKET_LAUNCHER_0001
    267 |
    NOTE: There are two name/value pairs named "PART_NUMBER" due to the 268 | inheritance 269 | of the "/" mapping in addition to the "/ammo" mapping. 270 |
    271 | 272 |
    273 |

    274 | 275 |

    276 |

    277 | 278 | 279 | Corporate Sales: 415/937-2555; Personal Sales: 415/937-3777; Government Sales: 415/937-3678
    280 | If you have any questions, please visit Customer Service, or contact your nearest sales office.

    281 | Copyright © 1997 Netscape Communications Corporation

    282 | This site powered by Netscape SuiteSpot servers. 283 | 284 |

    285 |

    286 | 287 | 288 | -------------------------------------------------------------------------------- /js-1.0/events.html: -------------------------------------------------------------------------------- 1 |

    Event handlers

    2 | 3 | 4 |
  • onBlur 5 |
  • onChange 6 |
  • onClick 7 |
  • onFocus 8 |
  • onLoad 9 |
  • onMouseOver 10 |
  • onSelect 11 |
  • onSubmit 12 |
  • onUnload 13 | 14 |
    15 | Display full contents 16 |
    -------------------------------------------------------------------------------- /js-1.0/expr.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript Values, Expressions, and Operators 5 | 6 | 7 | 8 | 9 |

    JavaScript Expressions and Operators

    10 | 11 | 23 | 24 |

    Expressions

    25 | 26 |

    27 | An expression is any valid set of literals, variables, operators, 28 | and expressions that evaluates to a single value. 29 | The value may be a number, a string, or a logical value. 30 | 31 | Conceptually, there are two types of expressions: 32 | those that assign a value to a variable, and those that simply 33 | have a value. For example, the expression 34 |

    35 | x = 7 36 |

    37 | is an expression that assigns x the value 7. This expression itself 38 | evaluates to 7. Such expressions use assignment operators. 39 | On the other hand, the expression 40 |

    41 | 3 + 4 42 |

    43 | simply evaluates to 7; it does not perform an assignment. The 44 | operators used in such expressions are referred to simply as operators. 45 |

    46 | JavaScript has the following kinds of expressions: 47 |

    52 |

    53 | The special keyword null denotes a null value. 54 | In contrast, variables that have not been assigned a value are undefined, and cannot 55 | be used without a run-time error. 56 | 57 |

    Conditional Expressions

    58 |

    59 | A conditional expression can have one of two values based on a condition. 60 | The syntax is 61 |

     62 | (condition) ? val1 : val2
     63 | 
    64 |

    65 | If condition is true, the expression has the value of val1, 66 | Otherwise it has the value of val2. 67 | You can use a conditional expression anywhere you would use a standard 68 | expression. 69 |

    70 | For example, 71 |

     72 | status = (age >= 18) ? "adult" : "minor"
     73 | 
    74 | This statement assigns the value "adult" to the variable status 75 | if age is eighteen or greater. Otherwise, it assigns the value 76 | "minor" to status. 77 | 78 |

    Assignment Operators (=, +=, -=, *=, /=)

    79 | 80 |

    81 | An assignment operator assigns a value to its left operand based 82 | on the value of its right operand. The basic assignment operator 83 | is equal (=), which assigns the value of its right operand to 84 | its left operand. That is, x = y assigns the value of y to x. 85 |

    86 | The other operators are shorthand for standard arithmetic operations 87 | as follows: 88 |

    95 | 96 |

    97 | There are additional assignment operators for bitwise operations: 98 |

    106 | 107 |

    Operators

    108 | 109 |

    110 | JavaScript has arithmetic, string, and logical operators. There 111 | are both binary and unary operators. A binary operator 112 | requires two operands, one before the operator and one after the 113 | operator: 114 |

    115 | operand1 operator operand2 116 |

    117 | For example, 118 | 3 + 4 or x * y 119 |

    120 | A unary operator requires a single operand, either before or after 121 | the operator: 122 |

    123 | operator operand 124 |

    125 | or 126 |

    127 | operand operator 128 |

    129 | For example x++ or ++x. 130 | 131 |

    Arithmetic Operators

    132 | 133 |

    134 | Arithmetic operators take numerical values (either literals or 135 | variables) as their operands and return a single numerical value. 136 | 137 |

    Standard Arithmetic Operators

    138 | 139 |

    140 | The standard arthmetic operators are addition (+), subtraction (-), multiplication (*), 141 | and division (/). These operators work in the standard way. 142 | 143 |

    Modulus (%)

    144 | 145 |

    146 | The modulus operator is used as follows: 147 |
    var1 % var2 148 |

    149 | The modulus operator returns the first operand modulo the second 150 | operand, that is, var1 modulo var2, in the statement 151 | above, where var1 and var2 are variables. The modulo 152 | function is the remainder of integrally dividing var1 by var2. 153 | For example, 12 % 5 returns 2. 154 | 155 |

    Increment (++)

    156 | 157 |

    158 | The increment operator is used as follows: 159 |
    160 | var++ or ++var 161 |

    162 | This operator increments (adds one to) its operand and returns a value. 163 | If used postfix, with operator after operand (for example x++), then it 164 | returns the value before incrementing. If used prefix with operator before 165 | operand (for example, ++x), then it returns the value after incrementing. 166 |

    167 | For example, if x is 3, then the statement 168 |

    169 | y = x++ 170 |

    171 | increments x to 4 and sets y to 3. 172 |

    173 | If x is 3, then the statement 174 |

    175 | y = ++x 176 |

    177 | increments x to 4 and sets y to 4. 178 | 179 |

    Decrement (--)

    180 | 181 |

    182 | The decrement operator is used as follows: 183 |

    184 | var-- or --var 185 |

    186 | This operator decrements (subtracts one from) its operand 187 | and returns a value. If used postfix (for example x--) then it 188 | returns the value before decrementing. If used prefix (for example, 189 | --x), then it returns the value after decrementing. 190 |

    191 | For example, if x is 3, then the statement 192 |

    193 | y = x-- 194 |

    195 | decrements x to 2 and sets y to 3. 196 |

    197 | If x is 3, then the statement 198 |

    199 | y = --x 200 |

    201 | decrements x to 2 and sets y to 2. 202 | 203 |

    Unary negation (-)

    204 | 205 |

    206 | The unary negation operator must precede its operand. It negates 207 | its operand. For example, 208 |

    209 | x = -x 210 |

    211 | negates the value of x; that is if x were 3, it would become -3. 212 | 213 |

    Bitwise Operators

    214 |

    215 | Bitwise operators treat their operands as a set of bits (zeros and ones), 216 | rather than as decimal, hexadecimal, or octal numbers. 217 | For example, the decimal number 9 has a binary representation of 1001. 218 | Bitwise operators perform their operations on such binary representations, 219 | but they return standard JavaScript numerical values. 220 | 221 |

    Bitwise Logical Operators

    222 | 223 |

    224 | The bitwise logical operators work conceptually as follows: 225 |

    233 |

    234 | The bitwise operators are: 235 |

    240 |

    241 | For example, the binary representation of 9 is 1001, and the binary representation 242 | of 15 is 1111. So, when the bitwise operators are applied to these values, 243 | the results are as follows: 244 |

    249 | 250 |

    Bitwise Shift Operators

    251 |

    252 | The bitwise shift operators are: 253 |

    258 | 259 |

    260 | The shift operators take two operands: the first is a quantity to be shifted, and the 261 | second specifies the number of bit positions by which the first operand is 262 | to be shifted. The direction of the shift operation is controlled by the operator used. 263 |

    264 | Shift operators convert their operands to 32-bit integers, and return a result of 265 | the same type as the left operator. 266 | 267 |

    Left Shift (<<)
    268 |

    269 | This operator shifts the first operand the specified number of bits to the left. 270 | Excess bits shifted off to the left are discarded. Zero bits are shifted in from 271 | the right. 272 |

    273 | For example, 9<<2 yields 36, because 1001 shifted two bits to the left becomes 100100, 274 | which is 36. 275 | 276 |

    Sign-propagating Right Shift (>>)
    277 |

    278 | This operator shifts the first operand the specified number of bits to the right. 279 | Excess bits shifted off to the right are discarded. 280 | Copies of the leftmost bit are shifted in from the left. 281 |

    282 | For example, 9>>2 yields 2, because 1001 shifted two bits to the right becomes 10, 283 | which is 2. Likewise, -9>>2 yields -3, because the sign is preserved. 284 | 285 |

    Zero-fill right shift (>>>)
    286 |

    287 | This operator shifts the first operand the specified number of bits to the left. 288 | Excess bits shifted off to the right are discarded. 289 | Zero bits are shifted in from the left. 290 | 291 |

    292 | For example, 19>>>2 yields 4, because 10011 shifted two bits to the right becomes 100, 293 | which is 4. For postive numbers, zero-fill right shift and sign-propagating right 294 | shift yield the same result. 295 | 296 | 297 |

    Logical Operators

    298 | 299 |

    300 | Logical operators take logical (Boolean) values as operands. 301 | They return a logical value. Logical values are true and false. 302 | 303 |

    And (&&)

    304 | 305 |

    306 | Usage: expr1 && expr2 307 |

    308 | The logical "and" operator returns true if both logical 309 | expressions expr1 and expr2 are true. Otherwise, 310 | it returns false. 311 | 312 |

    Or (||)

    313 | 314 |

    315 | Usage: expr1 || expr2 316 |

    317 | The logical "or" operator returns true if either logical 318 | expression expr1 or expr2 is true. If both expr1 319 | and expr2 are false, then it returns false. 320 | 321 |

    Not (!)

    322 | 323 |

    324 | Usage: !expr 325 |

    326 | The logical "not" operator is a unary operator that 327 | negates its operand expression 328 | expr. That is, if expr is true, it returns false, 329 | and if expr is false, then it returns true. 330 | 331 |

    Short-Circuit Evaluation

    332 |

    333 | As logical expressions are evaluated left to right, they are tested for 334 | possible "short circuit" evaluation using the following rule: 335 |

    339 |

    340 | The rules of logic guarantee that these evaluations will always be correct. 341 | Note that the anything part of the above expressions is not evaluated, so any 342 | side effects of doing so do not take effect. 343 | 344 | 345 |

    Comparison Operators (= =, >, >=, <, <=, !=)

    346 | 347 |

    348 | A comparison operator compares its operands and returns a logical 349 | value based on whether the comparison is true or not. The operands 350 | may be numerical or string values. When used on string values, 351 | the comparisons are based on the standard lexicographical ordering. 352 |

    353 | The operators are: 354 |

    371 | 372 |

    String Operators

    373 | 374 |

    375 | In addition to the comparison operators, which may be used on 376 | string values, the concatenation operator (+) concatenates two 377 | string values together, returning another string that is the union 378 | of the two operand strings. For example, 379 |

    380 | "my " + "string" 381 |

    382 | returns the string 383 |

    384 | "my string" 385 | 386 |

    387 | The shorthand assignment operator += can also be used to concatenate strings. 388 | For example, if the variable mystring is a string that has the value 389 | "alpha", then the expression 390 |

    mystring += "bet"
    391 | evaluates to "alphabet" and assigns this value to mystring. 392 | 393 |

    Operator Precedence

    394 | 395 |

    396 | The precedence of operators determines the order they are 397 | applied when evaluating an expression. You can override operator 398 | precedence by using parentheses. 399 |

    400 | The precedence of operators, from lowest to highest is as follows: 401 |

    402 |
    comma , 403 |
    assignment = += -= *= /= %= <<= >>= >>>= 404 | &= ^= |= 405 |
    conditional ?: 406 |
    logical-or || 407 |
    logical-and && 408 |
    bitwise-or | 409 |
    bitwise-xor ^ 410 |
    bitwise-and & 411 |
    equality == != 412 |
    relational < <= > >= 413 |
    bitwise shift << >> >>> 414 |
    addition/subtraction + - 415 |
    multiply/divide * / % 416 |
    negation/increment ! ~ - ++ -- 417 |
    call, member () [] . 418 |
    419 | 420 |

    421 | 422 | 423 | 424 | -------------------------------------------------------------------------------- /js-1.0/ident.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Values, Names, and Literals 4 | 5 | 6 | 7 | 8 |

    JavaScript Values, Names, and Literals

    9 | 14 | 15 |
    16 |

    Values

    17 | 18 |

    19 | JavaScript recognizes the following types of values: 20 |

    26 |

    27 | This relatively small set of types of values, or data types, 28 | enables you to perform useful functions with your applications. Notice that there 29 | is no explicit distinction between integer and real-valued numbers. Nor is there 30 | an explicit date data type in Navigator. However, the date object and related 31 | built-in functions enable you to handle dates. 32 |

    33 | Objects and functions are the other fundamental elements in the language. 34 | You can think of objects as named containers for values, and functions as procedures 35 | that your application can perform. 36 | 37 |

    Datatype Conversion

    38 |

    39 | JavaScript is a loosely typed language. That means that you do not have to specify 40 | the datatype of a variable when you declare it, and datatypes are converted 41 | automatically as needed during the course of script execution. So, for example, you could define a variable as follows: 42 |

     43 | var answer = 42
     44 | 
    45 |

    46 | And later, you could assign the same variable a string value, for example: 47 |

     48 | answer = "Thanks for all the fish..."
     49 | 
    50 |

    51 | Because JavaScript is loosely typed, this will not cause an error message. 52 |

    53 | In general, in expressions involving numeric and string values, JavaScript converts the numeric values to strings. 54 | For example, consider the following statements: 55 |

     56 | x = "The answer is " + 42
     57 | y = 42 + " is the answer."
     58 | 
    59 |

    60 | The first statement will the string "The answer is 42". The second statement will return the string "42 is the answer". 61 | 62 |

    63 | JavaScript provides several special functions for manipulating string and numeric values: 64 |

    70 | 71 |
    72 |

    Variables

    73 |

    74 | You use variables to hold values in your application. You 75 | give these variables names by which you reference them, 76 | and there are certain rules to which the names must conform. 77 |

    78 | A JavaScript identifier or name must start with a letter or 79 | underscore ("_"); subsequent characters can also be 80 | digits (0-9). Letters include the characters "A" through 81 | "Z" (uppercase) and the characters "a" through 82 | "z" (lowercase). 83 | JavaScript is case-sensitive. 84 |

    85 | Some examples of legal names are: 86 |

    91 | 92 |

    Variable scope

    93 |

    94 | The scope of a variable is where you can use it in a script. 95 | In JavaScript, there are two scopes that a variable can have: 96 |

    100 | 101 |

    102 | To declare a local variable inside a function, use the var keyword, 103 | for example: 104 |

    105 | var total = 0
    106 | 
    107 |

    108 | To declare a global variable, declare the variable by assignment, that is 109 | simply assign the desired value to the variable (either in a function or 110 | outside a function), for example: 111 |

    112 | total = 0
    113 | 
    114 |

    115 | It is good programming practice to 116 | declare global variables at the beginning of your script, so 117 | that functions will inherit the variable and its value. 118 | 119 | 120 |


    121 |

    Literals

    122 | 123 |

    124 | Literals are the way you represent values in JavaScript. 125 | These are fixed values that you literally provide in your 126 | application source, and are not variables. Examples of literals 127 | include: 128 |

    133 | 134 |

    Integers

    135 | 136 |

    137 | Integers can be expressed in decimal (base 10), hexadecimal (base 138 | 16), or octal (base 8) format. A decimal integer literal consists 139 | of a sequence of digits (optionally suffixed as described below) 140 | without a leading 0 (zero). 141 |

    142 | An integer can be expressed in octal or hexadecimal rather than 143 | decimal. A leading 0 (zero) on an integer literal means it is 144 | in octal; a leading 0x (or 0X) means hexadecimal. Hexadecimal 145 | integers can include digits (0-9) and the letters a-f and A-F. 146 | Octal integers can include only the digits 0-7. 147 | 148 |

    Floating Point Literals

    149 | 150 |

    151 | A floating point literal can have the following parts: a decimal 152 | integer, a decimal point ("."), a fraction (another 153 | decimal number), an exponent, and a type suffix. The exponent 154 | part is an "e" or "E" followed by an integer, which can be signed (preceded by 155 | a "+" or "-"). 156 | A floating point literal must have at least one digit, plus either 157 | a decimal point or "e" (or "E"). Some examples of floating point literals 158 | are: 159 |

    165 | 166 |

    Boolean Literals

    167 | 168 |

    169 | The boolean type has two literal values: true and false. 170 | 171 |

    String Literals

    172 |

    173 | A string literal is zero or more characters enclosed in double 174 | (") or single (') quotes. A string must be delimited by quotes 175 | of the same type; that is, either both single quotes or double 176 | quotes. The following are examples of string literals: 177 |

    183 | 184 |

    Special Characters

    185 |

    186 | You can use the following special characters in JavaScript string literals: 187 |

    194 | 195 |

    Escaping Characters

    196 |

    197 | You can insert quotes inside of strings by preceding them by a backslash. 198 | This is known as escaping the quotes. 199 | For example, 200 |

    201 | var quote = "He read \"The Cremation of Sam McGee\" by R.W. Service"
    202 | document.write(quote)
    203 | 
    204 |

    205 | The result of this would be

    206 | 210 | 211 | -------------------------------------------------------------------------------- /js-1.0/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | JavaScript Authoring Guide 4 | 5 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /js-1.0/introd.html: -------------------------------------------------------------------------------- 1 | 2 | Introduction 3 | 4 | 5 | 6 | 7 | Ongoing JavaScript Development 8 |

    9 | Development of the JavaScript language and its documentation 10 | continues. Additional features are planned; some current features 11 | could be modified if necessary. 12 |


    13 | 14 |

    Introduction

    15 | 16 | 21 | 22 |

    The JavaScript Language

    23 |

    24 |

    25 | JavaScript is a compact, object-based scripting language for developing client and server 26 | Internet applications. Netscape Navigator 2.0 interprets JavaScript statements embedded 27 | directly in an HTML page, and LiveWire enables you to create server-based applications similar 28 | to common gateway interface (CGI) programs. 29 |

    30 | In a client application for Navigator, JavaScript statements embedded in an HTML page can 31 | recognize and respond to user events such as mouse clicks, form input, and page navigation. 32 |

    33 | For example, you can write a JavaScript function to verify that users enter valid 34 | information into a form requesting a telephone number or zip code. 35 | Without any network transmission, an HTML page with embedded JavaScript can interpret 36 | the entered text and alert the user with a message dialog if the input is invalid. 37 | Or you can use JavaScript to perform an action (such as play an audio file, execute an applet, or communicate with a plug-in) in response to the user opening or exiting a page. 38 | 39 |


    40 |

    JavaScript and Java

    41 |

    42 | The JavaScript language resembles Java, but without Java's static 43 | typing and strong type checking. JavaScript supports most of Java's 44 | expression syntax and basic control flow constructs. In contrast to 45 | Java's compile-time system of classes built by declarations, 46 | JavaScript supports a run-time system based on a small number of 47 | data types representing numeric, Boolean, and string values. 48 | JavaScript has a simple instance-based object model that still provides 49 | significant capabilities. 50 | 51 |

    52 | JavaScript also supports functions, again without any special declarative 53 | requirements. Functions can be properties of 54 | objects, executing as loosely typed methods. 55 |

    56 | JavaScript complements Java by exposing useful properties of Java 57 | applets to script authors. JavaScript statements can get and set exposed properties to query the 58 | state or alter the performance of an applet or plug-in. 59 |

    60 | Java is an extension language designed, in particular, for fast 61 | execution and type safety. Type safety is reflected by being unable 62 | to cast a Java int into an object reference or to get at 63 | private memory by corrupting Java bytecodes. 64 |

    65 | Java programs consist exclusively of classes and their methods. Java's 66 | requirements for declaring classes, writing methods, and ensuring 67 | type safety make programming more complex than JavaScript authoring. 68 | Java's inheritance and strong typing also tend to require tightly 69 | coupled object hierarchies. 70 |

    71 | In contrast, JavaScript descends in spirit from a line of smaller, 72 | dynamically typed languages like HyperTalk and dBASE. These scripting 73 | languages offer programming tools to a much wider audience because of 74 | their easier syntax, specialized built-in functionality, and minimal 75 | requirements for object creation. 76 |

    77 | The following table compares and contrasts JavaScript and Java. 78 |

    79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 89 | 90 | 91 | 95 | 96 | 97 | 100 | 101 | 102 | 105 | 106 | 107 | 110 | 111 | 112 | 115 |
    JavaScriptJava
    Interpreted (not compiled) by client. 87 | Compiled on server before execution on client. 88 |
    Object-based. Code uses built-in, extensible objects, but no classes or 92 | inheritance. 93 | Object-oriented. Applets consist of object classes with inheritance. 94 |
    Code integrated with, and embedded in, HTML. 98 | Applets distinct from HTML (accessed from HTML pages). 99 |
    Variable data types not declared (loose typing). 103 | Variable data types must be declared (strong typing). 104 |
    Dynamic binding. Object references checked at run-time. 108 | Static binding. Object references must exist at compile-time. 109 |
    Cannot automatically write to hard disk. 113 | Cannot automatically write to hard disk. 114 |
    116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /js-1.0/keywords.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

    5 |

    Reserved words

    6 | 7 |

    The reserved words in this list cannot be used as JavaScript variables, functions, methods, or object names. Some of these words are keywords used in JavaScript; others are reserved for future use. 8 | 9 | 10 | 26 | 41 | 56 | 71 | 72 |
    11 |
  • abstract 12 |
  • boolean 13 |
  • break 14 |
  • byte 15 |
  • case 16 |
  • catch 17 |
  • char 18 |
  • class 19 |
  • const 20 |
  • continue 21 |
  • default 22 |
  • do 23 |
  • double 24 |
  • else 25 |
  • 27 |
  • extends 28 |
  • false 29 |
  • final 30 |
  • finally 31 |
  • float 32 |
  • for 33 |
  • function 34 |
  • goto 35 |
  • if 36 |
  • implements 37 |
  • import 38 |
  • in 39 |
  • instanceof 40 |
  • 42 |
  • int 43 |
  • interface 44 |
  • long 45 |
  • native 46 |
  • new 47 |
  • null 48 |
  • package 49 |
  • private 50 |
  • protected 51 |
  • public 52 |
  • return 53 |
  • short 54 |
  • static 55 |
  • 57 |
  • super 58 |
  • switch 59 |
  • synchronized 60 |
  • this 61 |
  • throw 62 |
  • throws 63 |
  • transient 64 |
  • true 65 |
  • try 66 |
  • var 67 |
  • void 68 |
  • while 69 |
  • with 70 |
  • 73 | 74 | 75 | 76 |


    77 | 80 | 81 | -------------------------------------------------------------------------------- /js-1.0/methods.html: -------------------------------------------------------------------------------- 1 |

    Methods and Functions

    2 | 3 | 4 | 5 |
  • abs 6 |
  • acos 7 |
  • alert 8 |
  • anchor 9 |
  • asin 10 |
  • atan 11 |
  • back 12 |
  • big 13 |
  • blink 14 |
  • blur 15 |
  • bold 16 |
  • ceil 17 |
  • charAt 18 |
  • clear 19 |
  • clearTimeout 20 |
  • click 21 |
  • close (document) 22 |
  • close (window) 23 |
  • confirm 24 |
  • cos 25 |
  • escape 26 |
  • eval 27 |
  • exp 28 |
  • fixed 29 |
  • floor 30 |
  • focus 31 |
  • fontcolor 32 |
  • fontsize 33 |
  • forward 34 |
  • getDate 35 |
  • getDay 36 |
  • getHours 37 |
  • getMinutes 38 |
  • getMonth 39 |
  • getSeconds 40 |
  • getTime 41 |
  • getTimezoneOffset 42 |
  • getYear 43 |
  • go 44 |
  • indexOf 45 |
  • isNaN 46 |
  • italics 47 |
  • lastIndexOf 48 |
  • link 49 |
  • log 50 |
  • max 51 |
  • min 52 |
  • open (document) 53 |
  • open (window) 54 |
  • parse 55 |
  • parseFloat 56 |
  • parseInt 57 |
  • pow 58 |
  • prompt 59 |
  • random 60 | 61 |
  • round 62 |
  • select 63 |
  • setDate 64 |
  • setHours 65 |
  • setMinutes 66 |
  • setMonth 67 |
  • setSeconds 68 |
  • setTimeout 69 |
  • setTime 70 |
  • setYear 71 |
  • sin 72 |
  • small 73 |
  • sqrt 74 |
  • strike 75 |
  • sub 76 |
  • submit 77 |
  • substring 78 |
  • sup 79 |
  • tan 80 |
  • toGMTString 81 |
  • toLocaleString 82 |
  • toLowerCase 83 |
  • toUpperCase 84 |
  • unescape 85 |
  • UTC 86 |
  • write 87 |
  • writeln 88 | 89 |
    90 | Display full contents 91 |
    -------------------------------------------------------------------------------- /js-1.0/model.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

    The JavaScript Object Model

    5 | 6 |

    JavaScript is based on a simple object-oriented paradigm. 7 | An object is a construct with properties that are JavaScript variables. 8 | Properties can be other objects. Functions associated with an object are known as the 9 | object's methods. 10 |

    11 | In addition to objects that are built into the Navigator client and the LiveWire server, 12 | you can define your own objects. 13 | 14 |

    19 | 20 |

    Objects and Properties

    21 | 22 |

    A JavaScript object has properties associated with it. You access the properties of an 23 | object with a simple notation: 24 |

     25 | objectName.propertyName
     26 | 
    27 |

    28 | Both the object name and property name are case sensitive. 29 | You define a property by assigning it a value. For example, suppose there is an object 30 | named myCar (we'll discuss how to create objects later-for now, just assume the object 31 | already exists). You can give it properties named make, model, 32 | and year as follows: 33 |

     34 | myCar.make = "Ford"
     35 | myCar.model = "Mustang"
     36 | myCar.year = 69;
     37 | 
    38 |

    39 | You can also refer to these properties using an array notation as follows: 40 |

     41 | mycar["make"] = "Ford
     42 | myCar["model"] = "Mustang"
     43 | myCar["year"] = 69;
     44 | 
    45 |

    This type of an array is known as an associative array, because each 46 | index element is also associated with a string value. To illustrate how this works, 47 | the following function displays the properties of the object, when you 48 | pass the object and the object's name as arguments to the function: 49 |

    function show_props(obj, obj_name) { 
     50 |     var result = "" 
     51 |     for (var i in obj) 
     52 |         result += obj_name + "." + i + " = " + obj[i] + "\n" 
     53 |     return result; 
     54 | } 
    55 | 56 |

    So, the function call show_props(myCar, "myCar") would 57 | return the following: 58 |

    myCar.make = Ford
     59 | myCar.model = Mustang
     60 | myCar.year = 67
    61 |

    62 | You may also define properties using ordinal numbers, for example: 63 |

     64 | temp[0] = 34
     65 | temp[1] = 42
     66 | temp[2] = 56
     67 | 
    68 | These statements create three properties of the object temp, and you must refer 69 | to these properties as temp[i], where i is an integer between 0 and 2. 70 | 71 | 72 | 73 |

    Functions and Methods

    74 |

    75 | Functions are one of the fundamental building blocks in JavaScript. 76 | A function is a JavaScript procedure--a set of statments that performs a specific task. 77 |

    78 | A function definition consists of the function keyword, followed by 79 |

    84 |

    85 | In a Navigator application, you can use any functions defined in the current page. 86 | It is generally a good idea to define all your functions in the HEAD of a page. 87 | When a user loads the page, the functions will then be loaded first. 88 | 89 |

    90 | The statements in a function can include other function calls defined for the 91 | current application. 92 | 93 |

    94 | For example, here is the definition of a simple function named pretty_print: 95 |

    96 | function pretty_print(string) { 97 | document.write("<HR><P>" + string) 98 | } 99 | 100 |

    101 | This function takes a string as its argument, adds some HTML tags to it using the concatenation 102 | operator (+), then displays the result to the current document. 103 |

    104 | Defining a function does not execute it. 105 | You have to call the function for it to do its work. 106 | For example, you could call the pretty_print function as follows: 107 |

    108 | <SCRIPT> 109 | pretty_print("This is some text to display") 110 | </SCRIPT> 111 | 112 |

    113 | The arguments of a function are not limited to just strings and numbers. 114 | You can pass whole objects to a function, too. 115 | The show_props function from the previous section is an example of a function that takes 116 | an object as an argument. 117 |

    118 | The arguments of a function are maintained in an array. 119 | Within a function, you can address the parameters passed to it as follows: 120 |

    121 | functionName.arguments[i]
    122 | 
    123 | where functionName is the name of the function and i is the ordinal 124 | number of the argument, starting at zero. So, the first argument passed to a function named 125 | myfunc would be myfunc.arguments[0]. The total number of arguments is indicated by the variable 126 | arguments.length. 127 | 128 |

    129 | A function can even be recursive, that is, it can call itself. For example, here is a function that computes factorials: 130 |

    131 | function factorial(n) {
    132 |   if ((n == 0) || (n == 1))
    133 |     return 1
    134 |   else {
    135 |     result = (n * factorial(n-1) )
    136 |     return result
    137 |   }
    138 | }
    139 | 
    140 | 141 |

    142 | You could then display the factorials of one through five as follows: 143 |

    144 | for (x = 0; x < 5; x++) {
    145 |    document.write(x, " factorial is ", factorial(x))
    146 |    document.write("
    ") 147 | } 148 |
    149 |

    150 | The results would be: 151 |
    152 | 0 factorial is 1 153 |
    1 factorial is 1 154 |
    2 factorial is 2 155 |
    3 factorial is 6 156 |
    4 factorial is 24 157 |
    5 factorial is 120 158 | 159 |

    Functions with Variable Numbers of Arguments

    160 |

    161 | You can call a function with more arguments than it is formally declared to accept 162 | using the arguments array. This is often useful if you don't know beforehand 163 | how many arguments will be passed to the function. 164 | You can use arguments.length to determine the number of arguments actually passed to the function,a 165 | and then treat each argument using the arguments array. 166 |

    167 | For example, consider a function defined to create HTML lists. 168 | The only formal argument for the function is a string that is "U" if the list is to be unordered 169 | (bulleted) or "O" if the list is to be ordered (numbered). The function is defined as follows: 170 |

    171 | function list(type) { 172 | document.write("<" + type + "L>") // begin list 173 | for (var i = 1; i < list.arguments.length; i++) // iterate through arguments 174 | document.write("<LI>" + list.arguments[i]) 175 | document.write("</" + type + "L>") // end list 176 | } 177 | 178 |

    179 | You can pass any number of arguments to this function and it will then display each argument as 180 | an item in the indicated type of list. For example, the following call to the function: 181 |

    182 | list("o", "one", 1967, "three", "etc, etc...")
    183 | 
    184 |

    185 | results in this output: 186 | 195 | 196 | 197 | 198 |

    Defining Methods

    199 |

    200 | A method is a function associated with an object. You define a method in the same way 201 | as you define a standard function. Then, use the following syntax to associate the function 202 | with an existing object: 203 |

    204 | object.methodname = function_name
    205 | 
    206 | where object is an existing object, methodname is the name you are assigning to 207 | the method, and function_name is the name of the function. 208 |

    209 | You can then call the method in the context of the object as follows: 210 |

    211 | object.methodname(params);
    212 | 
    213 | 214 |

    Using this for Object References

    215 |

    216 | JavaScript has a special keyword, this, that you can 217 | use to refer to the current object. For example, suppose you have a function called 218 | validate that validates an object's value property, given the object, and the 219 | high and low values: 220 |

    221 | function validate(obj, lowval, hival) {
    222 |    if ((obj.value < lowval) || (obj.value > hival))
    223 |       alert("Invalid Value!")
    224 | }
    225 | 
    226 |

    227 | Then, you could call validate in each form element's 228 | onChange event handler, using this to pass it the form element, as in the 229 | following example: 230 | 231 |

    232 | <INPUT TYPE = "text" NAME = "age" SIZE = 3 onChange="validate(this, 18, 99)"> 233 | 234 | 235 |

    236 | In general, in a method this refers to the calling object. 237 | 238 | 239 |

    Creating New Objects

    240 |

    241 | Both client and server JavaScript have a number of predefined objects. 242 | In addition, you can create your own objects. 243 | Creating your own object requires two steps: 244 |

    248 |

    249 | To define an object type, create a function for the object 250 | type that specifies its name, and its properties and methods. 251 | 252 | For example, suppose you want to create an object type for cars. 253 | You want this type of object to be called car, and you want it 254 | to have properties for make, model, year, and color. 255 | To do this, you would write the following function: 256 |

    257 | function car(make, model, year) {
    258 |    this.make = make; 
    259 |    this.model = model;
    260 |    this.year = year;
    261 | }
    262 | 
    263 |

    264 | Notice the use of this to assign values to the object's properties based 265 | on the values passed to the function. 266 |

    267 | Now you can create an object called mycar as follows: 268 |

    269 | mycar = new car("Eagle", "Talon TSi", 1993);
    270 | 
    271 |

    272 | This statement creates mycar and assigns it the specified values for its properties. 273 | Then the value of mycar.make is the string "Eagle", mycar.year 274 | is the integer 1993, and so on. 275 |

    276 | You can create any number of car objects by calls to new. 277 | For example, 278 |

    279 | kenscar = new car("Nissan", "300ZX", 1992)
    280 | 
    281 |

    282 | An object can have a property that is itself another object. 283 | For example, suppose I define an object called person as follows: 284 |

    285 | function person(name, age, sex) {
    286 |    this.name = name;
    287 |    this.age = age;
    288 |    this.sex = sex;
    289 | }
    290 | 
    291 |

    292 | And then instantiate two new person objects as follows: 293 |

    294 | rand = new person("Rand McNally", 33, "M")
    295 | ken = new person("Ken Jones", 39, "M")
    296 | 
    297 |

    298 | Then we can rewrite the definition of car to include an owner property 299 | that takes a person object, as follows: 300 |

    301 | function car(make, model, year, owner) {
    302 |    this.make = make; 
    303 |    this.model = model;
    304 |    this.year = year;
    305 |    this.owner = owner;
    306 | }
    307 | 
    308 |

    309 | To instantiate the new objects, you then use the following: 310 |

    311 | car1 = new car("Eagle", "Talon TSi", 1993, rand);
    312 | car2 = new car("Nissan", "300ZX", 1992, ken)
    313 | 
    314 |

    315 | Notice that instead of passing a literal string or integer value when creating the 316 | new objects, the above statements pass the objects rand and ken as the arguments for the owners. 317 | Then if you want to find out the name of the owner of car2, 318 | you can access the following property: 319 |

    320 | car2.owner.name
    321 | 
    322 |

    323 | Note that you can always add a property to a previously defined object. 324 | For example, the statement: 325 |

    326 | car1.color = "black"
    327 | 
    328 | adds a property color to car1, and assigns it a value of "black". 329 | However, this does not affect any other objects. 330 | To add the new property to all objects of the same type, you have to add the property to the 331 | definition of the car object type. 332 | 333 |

    Defining Methods

    334 |

    335 | You can define methods for an object type by including a method defnition in the 336 | object type definition. For example, suppose you have a set of image GIF files, 337 | and you want to define a method that displays the information for the cars, along with the 338 | corresponding image. You could define a function such as: 339 |

    340 | function displayCar() {
    341 |    var result = "A Beautiful " + this.year 
    342 |                 + " " + this.make + " " + this.model;
    343 |    pretty_print(result)
    344 | }
    345 | 
    346 | where pretty_print is the previously defined function to display a string. 347 | Notice the use of this to refer to the object to which the method belongs. 348 |

    349 | You can make this function a method of car by adding the statement 350 |

    this.displayCar = displayCar;
    351 | to the object definition. So, the full definition of car would now 352 | look like: 353 | 354 |
    355 | function car(make, model, year, owner) {
    356 |    this.make = make; 
    357 |    this.model = model;
    358 |    this.year = year;
    359 |    this.owner = owner;
    360 |    this.displayCar = displayCar;
    361 | }
    362 | 
    363 |

    364 | Then you can call this new method as follows: 365 |

    366 | car1.displayCar()
    367 | car2.displayCar()
    368 | 
    369 | This will produce output like this: 370 |

    371 |


    372 | A Beautiful 1993 Eagle Talon TSi 373 |

    374 |


    375 | A Beautiful 1992 Nissan 300ZX 376 | 377 | 378 | -------------------------------------------------------------------------------- /js-1.0/navbar.html: -------------------------------------------------------------------------------- 1 | Button Bar 2 |
    3 |
    4 | 19 | -------------------------------------------------------------------------------- /js-1.0/navobj.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

    Navigator Objects

    5 | 6 | 12 | 13 | 14 |

    Using Navigator Objects

    15 |

    16 | When you load a page in Navigator, it creates a number of objects corresponding 17 | to the page, its contents, and other pertinent information. 18 |

    19 | Every page always has the following objects: 20 |

      21 |
    • window: the top-level object; contains properties that apply to the entire window. 22 | There is also a window object for each for "child window" in a frames document. 23 |
    • location: contains properties on the current URL 24 |
    • history: contains properties representing URLs 25 | the user has previously visited 26 |
    • document: contains properties for content in the current document, 27 | such as title, background color, and forms 28 |
    29 | 30 |

    31 | The properties of the document object are largely content-dependent. 32 | That is, they are created based on the content that you put in the document. 33 | For example, the document object has a property for each form and each anchor 34 | in the document. 35 |

    36 | For example, suppose you create a page named simple.html that contains the following 37 | HTML: 38 |

    39 | <TITLE>A Simple Document</TITLE> 40 | <BODY><FORM NAME="myform" ACTION="FormProc()" METHOD="get" >Enter a value: <INPUT TYPE=text NAME="text1" VALUE="blahblah" SIZE=20 > 41 | Check if you want: 42 | <INPUT TYPE="checkbox" NAME="Check1" CHECKED onClick="update(this.form)"> Option #1 43 | <P> 44 | <INPUT TYPE="button" NAME="Button1" VALUE="Press Me" onClick="update(this.form)"> 45 | </FORM></BODY> 46 | 47 |

    48 | As always, there would be window, location, history, and document objects. 49 | These would have properties such as: 50 |

      51 |
    • location.href = "http://www.terrapin.com/samples/vsimple.html" 52 |
    • document.title = "A Simple Document" 53 |
    • document.fgColor = #000000 54 |
    • document.bgColor = #ffffff 55 |
    • history.length = 7 56 |
    57 |

    58 | These are just some example values. In practice, these values would be based 59 | on the document's actual location, its title, foreground and background colors, 60 | and so on. 61 |

    62 | Navigator would also create the following objects based on the contents of the page: 63 |

      64 |
    • document.myform 65 |
    • document.myform.Check1 66 |
    • document.myform.Button1 67 |
    68 |

    69 | These would have properties such as: 70 |

      71 |
    • document.myform.action = http://terrapin/mocha/formproc() 72 |
    • document.myform.method = get 73 |
    • document.myform.length = 5 74 |
    • document.myform.Button1.value = Press Me 75 |
    • document.myform.Button1.name = Button1 76 |
    • document.myform.text1.value = blahblah 77 |
    • document.myform.text1.name = text1 78 |
    • document.myform.Check1.defaultChecked = true 79 |
    • document.myform.Check1.value = on 80 |
    • document.myform.Check1.name = Check1 81 |
    82 |

    83 | Notice that each of the property references above starts with "document," 84 | followed by the name of the form, "myform," and then the property name (for form properties) 85 | or the name of the form element. 86 | This sequence follows the Navigator's object hierarchy, discussed in the next section. 87 | 88 | 89 |


    90 |

    Navigator Object Hierarchy

    91 |

    92 | The objects in Navigator exist in a hierarchy that reflects the 93 | hierarchical structure of the HTML page itself. 94 | Although you cannot derive object classes from these objects, 95 | as you can in languages such as Java, it is useful to understand the Navigator's 96 | JavaScript object hierarchy. 97 | In the strict object-oriented sense, this type of hierarchy is known 98 | as an instance hierarchy, since it concerns specific instances of 99 | objects rather than object classes. 100 |

    101 | In this hierarchy, an object's "descendants" are properties of the object. 102 | For example, a form named "form1" is an object, but is also a property of document, 103 | and is referred to as "document.form1". 104 | 105 | The Navigator object hierarchy is illustrated below: 106 | 107 |

    108 | navigator 109 | 110 | window 111 | | 112 | +--parent, frames, self, top 113 | | 114 | +--location 115 | | 116 | +--history 117 | | 118 | +--document 119 | | 120 | +--forms 121 | | | 122 | | elements (text fields, textarea, checkbox, password 123 | | radio, select, button, submit, reset) 124 | +--links 125 | | 126 | +--anchors 127 | 128 | 129 |

    130 | To refer to specific properties of these objects, you must specify the object 131 | name and all its ancestors. 132 | Exception: You are not required to include the window object. 133 | 134 | 135 |


    136 |

    JavaScript and HTML Layout

    137 |

    138 | To use JavaScript properly in the Navigator, it is important to have a basic understanding of how 139 | the Navigator performs layout. Layout refers to transforming the plain text directives 140 | of HTML into graphical display on your computer. Generally speaking, layout happens sequentially 141 | in the Navigator. That is, the Navigator starts from the top of the HTML file and works its way 142 | down, figuring out how to display output to the screen as it goes. So, it starts with the HEAD of 143 | an HTML document, then starts at the top of the BODY and works its way down. 144 |

    145 | Because of this "top-down" behavior, JavaScript only reflects HTML that it has encountered. 146 | For example, suppose you define a form with a couple of text input elments: 147 |

    148 | <FORM NAME="statform"> 149 | <input type = "text" name = "username" size = 20> 150 | <input type = "text" name = "userage" size = 3> 151 | 152 |

    153 | Then these form elements are reflected as JavaScript objects document.statform.username 154 | and document.statform.userage, that you can use anywhere after the form is defined. 155 | However, you could not use these objects before the form is defined. 156 | So, for example, you could display the value of these objects in a script after the form definition: 157 |

    158 | <SCRIPT> 159 | document.write(document.statform.username.value) 160 | document.write(document.statform.userage.value) 161 | </SCRIPT> 162 | 163 |

    164 | However, if you tried to do this before the form definition (i.e. above it in the HTML page), 165 | you would get an error, since the objects don't exist yet in the Navigator. 166 |

    167 | Likewise, once layout has occured, setting a property value does not affect its value or 168 | its appearance. For example, suppose you have a document title defined as follows" 169 |

    170 | <TITLE>My JavaScript Page</TITLE> 171 | 172 |

    173 | This is reflected in JavaScript as the value of document.title. Once the Navigator 174 | has displayed this in layout (in this case, in the title bar of the Navigator window), you cannot 175 | change the value in JavaScript. 176 | So, if later in the page, you have the following script: 177 |

    178 | document.title = "The New Improved JavaScript Page"
    179 | 
    180 |

    181 | it will not change the value of document.title nor affect the appearance of the page, 182 | nor will is generate an error. 183 | 184 | 185 | 186 |


    187 |

    Key Navigator Objects

    188 |

    189 | Some of the most useful Navigator objects include document, form, and window. 190 | 191 | 192 |

    Using the document Object

    193 |

    194 | One of the most useful Navigator objects is the document object, because its 195 | write and writeln methods can generate HTML. 196 | These methods are the way that you display JavaScript expressions to the user. 197 | The only difference between write and writeln is that writeln adds a carriage return 198 | at the end of the line. However, since HTML ignores carriage returns, this will 199 | only affect preformatted text, such as that inside a PRE tag. 200 |

    201 | The document object also has onLoad and onUnload event-handlers to perform 202 | functions when a user first loads a page and when a user exits a page. 203 |

    204 | There is only one document object for a page, and it is the ancestor for all the 205 | form, link, and anchor objects in the page. 206 | 207 | 208 | 209 |

    Using the form Object

    210 |

    211 | Navigator creates a form object for each form in a document. 212 | You can name a form with the NAME attribute, as in this example: 213 |

    214 | <FORM NAME="myform"> 215 | <INPUT TYPE="text" NAME="quantity" onChange="..."> 216 | ... 217 | </FORM> 218 | 219 |

    220 | There would be a JavaScript object named myform based on this form. 221 | The form would have a property corresponding to the text object, 222 | that you would refer to as 223 | 224 |

    225 | document.myform.quantity 226 | 227 | 228 | You would refer to the value property of this object as 229 | 230 | 231 | document.myform.quantity.value 232 | 233 | 234 |

    235 | The forms in a document are stored in an array called forms. 236 | The first (topmost in the page) form is forms[0], 237 | the second forms[1], and so on. 238 | So the above references could also be: 239 |

    240 | document.forms[0].quantity 241 | document.forms[0].quantity.value 242 | 243 |

    244 | Likewise, the elements in a form, such as text fields, radio buttons, and so on, 245 | are stored in an elements array. 246 | 247 | 253 | 254 | 255 |

    Using the window Object

    256 |

    257 | The window object is the "parent" object for all other objects in Navigator. 258 | You can always omit the object name in references to window properties and methods. 259 | 260 |

    261 | Window has several very useful methods that create new windows and 262 | pop-up dialog boxes: 263 |

      264 |
    • open and close: Opens and closes a browser window 265 |
    • alert: Pops up an alert dialog box 266 |
    • confirm: Pops up a confirmation dialog box 267 |
    268 | 269 |

    270 | The window object has properties for all the frames in a frameset. 271 | The frames are stored in the frames array. 272 | The frames array contains an entry for each child frame in a window. For example, if a 273 | window contains three child frames, these frames are reflected as window.frames[0], 274 | window.frames[1], and window.frames[2]. 275 | 276 |

    277 | The status property enables you to set the message in the status bar 278 | at the bottom of the client window. 279 | 280 | 281 | 282 | -------------------------------------------------------------------------------- /js-1.0/objects.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

    4 |

    Objects

    5 | 6 | 7 | 8 |
  • anchor (anchors array) 9 |
  • button 10 |
  • checkbox 11 |
  • Date 12 |
  • document 13 |
  • elements array 14 |
  • form (forms array) 15 |
  • frame (frames array) 16 |
  • hidden 17 |
  • history 18 |
  • link (links array) 19 |
  • location 20 | 21 |
  • Math 22 |
  • navigator 23 |
  • password 24 |
  • radio 25 |
  • reset 26 |
  • select (options array) 27 |
  • string 28 |
  • submit 29 |
  • text 30 |
  • textarea 31 |
  • window 32 | 33 |
    34 | Display full contents 35 |
    36 | 37 | -------------------------------------------------------------------------------- /js-1.0/props.html: -------------------------------------------------------------------------------- 1 |

    Properties

    2 | 3 | 4 | 5 |
  • action 6 |
  • alinkColor 7 |
  • anchors 8 |
  • appCodeName 9 |
  • appName 10 |
  • appVersion 11 |
  • bgColor 12 |
  • checked 13 |
  • cookie 14 |
  • defaultChecked 15 |
  • defaultSelected 16 |
  • defaultStatus 17 |
  • defaultValue 18 |
  • E 19 |
  • elements 20 |
  • encoding 21 |
  • fgColor 22 |
  • forms 23 |
  • frames 24 | 25 |
  • hash 26 |
  • host 27 |
  • hostname 28 |
  • href 29 |
  • index 30 |
  • lastModified 31 |
  • length 32 |
  • linkColor 33 |
  • links 34 |
  • LN2 35 |
  • LN10 36 |
  • location 37 |
  • LOG2E 38 |
  • LOG10E 39 |
  • method 40 |
  • name 41 |
  • options 42 |
  • parent 43 |
  • pathname 44 | 45 |
  • PI 46 |
  • port 47 |
  • protocol 48 |
  • referrer 49 |
  • search 50 |
  • selected 51 |
  • selectedIndex 52 |
  • self 53 |
  • SQRT1_2 54 |
  • SQRT2 55 |
  • status 56 |
  • target 57 |
  • text 58 |
  • title 59 |
  • top 60 |
  • userAgent 61 |
  • value 62 |
  • vlinkColor 63 |
  • window 64 | 65 |
    66 | Display full contents 67 |
    -------------------------------------------------------------------------------- /js-1.0/ref_d-e.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

    Date object

    5 |

    Lets you work with dates and times. 6 | 7 |

    Syntax

    8 |

    To create a Date object: 9 |

     10 | 1. dateObjectName = new Date()
     11 | 2. dateObjectName = new Date("month day, year hours:minutes:seconds")
     12 | 3. dateObjectName = new Date(year, month, day)
     13 | 4. dateObjectName = new Date(year, month, day, hours, minutes, seconds)
     14 | 
    15 | dateObjectName is either the name of a new object or a property of an existing object. 16 |
    month, day, year, hours, minutes, and seconds are string values for form 2 of the syntax. For forms 3 and 4, they are integer values. 17 | 18 |

    To use Date methods: 19 |

     20 | dateObjectName.methodName(parameters)
     21 | 
    22 | dateObjectName is either the name of an existing Date object or a property of an existing object.. 23 |
    methodName is one of the methods listed below. 24 | 25 |

    Exceptions: The Date object's parse and UTC methods are static methods that you use as follows: 26 |

     27 | Date.UTC(parameters)
     28 | Date.parse(parameters)
     29 | 
    30 | 31 | 32 |

    Property of

    33 |
  • None. 34 | 35 | 36 |

    Description

    37 |

    The Date object is a built-in JavaScript object. 38 | 39 |

    Form 1 of the syntax creates today's date and time. If you omit hours, minutes, or seconds from form 2 or 4 of the syntax, the value will be set to zero. 40 | 41 |

    The way JavaScript handles dates is very similar to the way Java handles dates: both languages have many of the same date methods, and both store dates internally as the number of milliseconds since January 1, 1970 00:00:00. Dates prior to 1970 are not allowed. 42 | 43 | 44 |

    Properties

    45 |
  • None. 46 | 47 | 48 |

    Methods

    49 |
  • getDate 50 |
  • getDay 51 |
  • getHours 52 |
  • getMinutes 53 |
  • getMonth 54 |
  • getSeconds 55 |
  • getTime 56 |
  • getTimezoneOffset 57 |
  • getYear 58 |
  • parse 59 |
  • setDate 60 |
  • setHours 61 |
  • setMinutes 62 |
  • setMonth 63 |
  • setSeconds 64 |
  • setTime 65 |
  • setYear 66 |
  • toGMTString 67 |
  • toLocaleString 68 |
  • UTC 69 | 70 | 71 |

    Event handlers

    72 |
  • None. Built-in objects do not have event handlers. 73 | 74 | 75 |

    Examples

    76 |

    77 |

    today = new Date() 78 | birthday = new Date("December 17, 1995 03:24:00") 79 | birthday = new Date(95,12,17) 80 | birthday = new Date(95,12,17,3,24,0) 81 | 82 | 83 | 84 | 85 |
    86 |

    defaultChecked property

    87 |

    88 | A Boolean value indicating the default selection state of a checkbox or radio button. 89 | 90 |

    Syntax

    91 |
     92 | 1. checkboxName.defaultChecked
     93 | 2. radioName[index].defaultChecked
     94 | 
    95 |

    checkboxName is either the value of the NAME attribute of a checkbox object or an element in the elements array. 96 |
    radioName is the value of the NAME attribute of a radio object. 97 |
    index is an integer representing a radio button in a radio object. 98 | 99 |

    Property of

    100 |

    checkbox, radio 101 | 102 |

    Description

    103 |

    If an checkbox or radio button is selected by default, the value of the defaultChecked property is true; otherwise, it is false. defaultChecked initially reflects whether the CHECKED attribute is used within an <INPUT> tag; however, setting defaultChecked overrides the CHECKED attribute. 104 | 105 |

    You can set the defaultChecked property at any time. The display of the checkbox or radio button does not update when you set the defaultChecked property, only when you set the checked property. 106 | 107 |

    Examples

    108 |

    The following example resets an array of radio buttons called musicType on the musicForm form to the default selection state. 109 | 110 |

    111 | function radioResetter() {
    112 |    var i=""
    113 |    for (i in document.musicForm.musicType) {
    114 |       if (document.musicForm.musicType[i].defaultChecked==true) {
    115 |          document.musicForm.musicType[i].checked=true
    116 |       }
    117 |    }
    118 | }
    119 | 
    120 | 121 |

    See also

    122 |
  • checked property 123 | 124 |
    125 |

    defaultSelected property

    126 |

    127 | A Boolean value indicating the default selection state of an option in a select object. 128 | 129 |

    Syntax

    130 |
    selectName.options[index].defaultSelected
    131 |

    selectName is either the value of the NAME attribute of a select object or an element in the elements array. 132 |
    index is an integer representing an option in a select object. 133 | 134 |

    Property of

    135 |

    options array 136 | 137 |

    Description

    138 |

    If an option in a select object is selected by default, the value of the defaultSelected property is true; otherwise, it is false. defaultSelected initially reflects whether the SELECTED attribute is used within an <OPTION> tag; however, setting defaultSelected overrides the SELECTED attribute. 139 | 140 |

    You can set the defaultSelected property at any time. The display of the select object does not update when you set the defaultSelected property, only when you set the selected or selectedIndex properties. 141 | 142 |

    A select object created without the MULTIPLE attribute can have only one option selected by default. When you set defaultSelected in such an object, any previous default selections, including defaults set with the SELECTED attribute, are cleared. If you set defaultSelected in a select object created with the MULTIPLE attribute, previous default selections are not affected. 143 | 144 |

    Examples

    145 |

    In the following example, the restoreDefault() function returns the musicType select object to its default state. The for loop uses the options array to evaluate every option in the select object. The if statement sets the selected property if defaultSelected is true. 146 |

    147 | function restoreDefault() {
    148 |    for (var i = 0; i < document.musicForm.musicType.length; i++) {
    149 |       if (document.musicForm.musicType.options[i].defaultSelected == true) {
    150 |          document.musicForm.musicType.options[i].selected=true
    151 |       }
    152 |    }
    153 | }
    154 | 
    155 | The previous example assumes that the select object is similar to the following: 156 |
    157 | <SELECT NAME="musicType"> 
    158 |    <OPTION SELECTED> R&B
    159 |    <OPTION> Jazz
    160 |    <OPTION> Blues
    161 |    <OPTION> New Age
    162 | </SELECT>
    163 | 
    164 | 165 |

    See also

    166 |
  • index, selected, selectedIndex properties 167 | 168 |
    169 |

    defaultStatus property

    170 |

    171 | The default message displayed in the status bar at the bottom of the window. 172 | 173 |

    Syntax

    174 |
    windowReference.defaultStatus
    175 |

    windowReference is a valid way of referring to a window, as described in the window object. 176 | 177 |

    Property of

    178 |

    window 179 | 180 |

    Description

    181 |

    The defaultStatus message appears when nothing else is in the status bar. Do not confuse the defaultStatus property with the status property. The status property reflects a priority or transient message in the status bar, such as the message that appears when a mouseOver event occurs over an anchor. 182 | 183 |

    You can set the defaultStatus property at any time. You must return true if you want to set the defaultStatus property in the onMouseOver event handler. 184 | 185 | 186 |

    Examples

    187 |

    In the following example, the statusSetter() function sets both the status and defaultStatus properties in an onMouseOver event handler: 188 | 189 |

    190 | function statusSetter() {
    191 |    window.defaultStatus = "Click the link for the Netscape home page"
    192 |    window.status = "Netscape home page"
    193 | }
    194 | 
    195 | <A HREF="http://www.netscape.com"
    196 |    onMouseOver = "statusSetter(); return true">Netscape</A>
    197 | 
    198 | 199 | In the previous example, notice that the onMouseOver event handler returns a value of true. You must return true to set status or defaultStatus in an event handler. 200 | 201 |

    See also

    202 |
  • status property 203 | 204 |
    205 |

    defaultValue property

    206 |

    207 | A string indicating the default value of a password, text, or textarea object. 208 | 209 |

    Syntax

    210 |
    211 | 1. passwordName.defaultValue
    212 | 2. textName.defaultValue
    213 | 3. textareaName.defaultValue
    214 | 
    215 |

    passwordName is either the value of the NAME attribute of a password object or an element in the elements array. 216 |
    textName is either the value of the NAME attribute of a text object or an element in the elements array. 217 |
    textareaName is either the value of the NAME attribute of a textarea object or an element in the elements array. 218 | 219 |

    Property of

    220 |

    password, text, textarea 221 | 222 |

    Description

    223 |

    The initial value of defaultValue differs for each object: 224 |

  • For text objects, it initially reflects the value of the VALUE attribute. 225 |
  • For textarea objects, it initially reflects the value specified between the <TEXTAREA> and </TEXTAREA> tags. 226 |
  • For password objects, it initially is null (for security reasons), regardless of the value of the VALUE attribute. 227 | 228 |

    Setting defaultValue programatically overrides the initial setting. If you programatically set defaultValue for the password object and then evaluate it, JavaScript returns the current value. 229 | 230 |

    You can set the defaultValue property at any time. The display of the related object does not update when you set the defaultValue property, only when you set the value property. 231 | 232 |

    Examples

    233 |

    The following function evaluates the defaultValue property of objects on the surfCity form and displays the values in the msgWindow window: 234 |

    235 | function defaultGetter() {
    236 |    msgWindow=window.open("")
    237 |    msgWindow.document.write("hidden.defaultValue is " +
    238 |       document.surfCity.hiddenObj.defaultValue + "<BR>")
    239 |    msgWindow.document.write("password.defaultValue is " +
    240 |       document.surfCity.passwordObj.defaultValue + "<BR>")
    241 |    msgWindow.document.write("text.defaultValue is " +
    242 |       document.surfCity.textObj.defaultValue + "<BR>")
    243 |    msgWindow.document.write("textarea.defaultValue is " +
    244 |       document.surfCity.textareaObj.defaultValue + "<BR>")
    245 |    msgWindow.document.close()
    246 | }
    247 | 
    248 | 249 |

    See also

    250 |
  • value property 251 | 252 |
    253 |

    document object

    254 |

    Contains information on the current document, and provides methods for displaying HTML output to the user. 255 | 256 | 257 |

    Syntax

    258 |

    To define a document object, use standard HTML syntax: 259 |

    260 | <BODY
    261 |    BACKGROUND="backgroundImage"
    262 |    BGCOLOR="backgroundColor"
    263 |    TEXT="foregroundColor"
    264 |    LINK="unfollowedLinkColor"
    265 |    ALINK="activatedLinkColor"
    266 |    VLINK="followedLinkColor"
    267 |    [onLoad="handlerText"]
    268 |    [onUnload="handlerText"]>
    269 | </BODY>
    270 | 
    271 | BACKGROUND specifies an image that fills the background of the document. 272 |
    BGCOLOR, TEXT, LINK, ALINK, 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. 273 | 274 |

    To use a document object's properties and methods: 275 |

    276 | 1. document.propertyName
    277 | 2. document.methodName(parameters)
    278 | 
    279 | propertyName is one of the properties listed below. 280 |
    methodName is one of the methods listed below. 281 | 282 | 283 |

    Property of

    284 |
  • window 285 | 286 | 287 |

    Description

    288 |

    An HTML document consists of a <HEAD> and <BODY> tag. The <HEAD> includes information on the document's title and base (the absolute URL base to be used for relative URL links in the document). The <BODY> tag encloses the body of a document, which is defined by the current URL. The entire body of the document (all other HTML elements for the document) goes within the <BODY> tag. 289 | 290 |

    You can load a new document by using the location object. 291 | 292 |

    You can reference the anchors, forms, and links of a document by using the anchors, forms, and links arrays. These arrays contain an entry for each anchor, form, or link in a document. 293 | 294 | 295 |

    Properties

    296 |
  • alinkColor reflects the ALINK attribute 297 |
  • anchors is an array reflecting all the anchors in a document 298 |
  • bgColor reflects the BGCOLOR attribute 299 |
  • cookie specifies a cookie 300 |
  • fgColor reflects the TEXT attribute 301 |
  • forms is an array reflecting all the forms in a document 302 |
  • lastModified reflects the date a document was last modified 303 |
  • linkColor reflects the LINK attribute 304 |
  • links is an array reflecting all the links in a document 305 |
  • location reflects the complete URL of a document 306 |
  • referrer reflects the URL of the calling document 307 |
  • title reflects the contents of the <TITLE> tag 308 |
  • vlinkColor reflects the VLINK attribute 309 | 310 |

    The following objects are also properties of the document object: 311 |

  • anchor 312 |
  • form 313 |
  • history 314 |
  • link 315 | 316 | 317 |

    Methods

    318 |
  • clear 319 |
  • close 320 |
  • open 321 |
  • write 322 |
  • writeln 323 | 324 | 325 |

    Event handlers

    326 |
  • None. The onLoad and onUnload event handlers are specified in the <BODY> tag but are actually event handlers for the window object. 327 | 328 | 329 |

    Examples

    330 |

    The following example creates two frames, each with one document. The document in the first frame contains links to anchors in the document of the second frame. Each document defines its colors. 331 | 332 |

    DOC0.HTML, which defines the frames, contains the following code: 333 |

    334 | <HTML> 335 | <HEAD> 336 | <TITLE>Document object example</TITLE> 337 | </HEAD> 338 | <FRAMESET COLS="30%,70%"> 339 | <FRAME SRC="doc1.html" NAME="frame1"> 340 | <FRAME SRC="doc2.html" NAME="frame2"> 341 | </FRAMESET> 342 | </HTML> 343 | 344 | 345 |

    DOC1.HTML, which defines the content for the first frame, contains the following code: 346 |

    347 | <HTML> 348 | <SCRIPT> 349 | </SCRIPT> 350 | <BODY 351 | BGCOLOR="antiquewhite" 352 | TEXT="darkviolet" 353 | LINK="fuchsia" 354 | ALINK="forestgreen" 355 | VLINK="navy"> 356 | <P><B>Some links</B> 357 | <LI><A HREF="doc2.html#numbers" TARGET="frame2">Numbers</A> 358 | <LI><A HREF="doc2.html#colors" TARGET="frame2">Colors</A> 359 | <LI><A HREF="doc2.html#musicTypes" TARGET="frame2">Music types</A> 360 | <LI><A HREF="doc2.html#countries" TARGET="frame2">Countries</A> 361 | </BODY> 362 | </HTML> 363 | 364 | 365 |

    DOC2.HTML, which defines the content for the second frame, contains the following code: 366 |

    367 | <HTML> 368 | <SCRIPT> 369 | </SCRIPT> 370 | <BODY 371 | BGCOLOR="oldlace" onLoad="alert('Hello, World.')" 372 | TEXT="navy"> 373 | <P><A NAME="numbers"><B>Some numbers</B></A> 374 | <LI>one 375 | <LI>two 376 | <LI>three 377 | <LI>four 378 | <LI>five 379 | <LI>six 380 | <LI>seven 381 | <LI>eight 382 | <LI>nine 383 | <P><A NAME="colors"><B>Some colors</B></A> 384 | <LI>red 385 | <LI>orange 386 | <LI>yellow 387 | <LI>green 388 | <LI>blue 389 | <LI>purple 390 | <LI>brown 391 | <LI>black 392 | <P><A NAME="musicTypes"><B>Some music types</B></A> 393 | <LI>R&B 394 | <LI>Jazz 395 | <LI>Soul 396 | <LI>Reggae 397 | <LI>Rock 398 | <LI>Country 399 | <LI>Classical 400 | <LI>Opera 401 | <P><A NAME="countries"><B>Some countries</B></A> 402 | <LI>Afghanistan 403 | <LI>Brazil 404 | <LI>Canada 405 | <LI>Finland 406 | <LI>India 407 | <LI>Italy 408 | <LI>Japan 409 | <LI>Kenya 410 | <LI>Mexico 411 | <LI>Nigeria 412 | </BODY> 413 | </HTML> 414 | 415 | 416 | 417 |

    See also

    418 |
  • frame and window objects 419 | 420 | 421 | 422 |
    423 |

    E property

    424 |

    425 | Euler's constant and the base of natural logarithms, approximately 2.718. 426 | 427 |

    Syntax

    428 |
    Math.E
    429 | 430 |

    Property of

    431 |

    Math 432 | 433 |

    Description

    434 |

    Because E is a constant, it is a read-only property of Math. 435 | 436 |

    Examples

    437 |

    The following example displays Euler's constant: 438 |

    document.write("Euler's constant is " + Math.E)
    439 | 440 |

    See also

    441 |
  • LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2 properties 442 | 443 |
    444 |

    elements array

    445 |

    An array of objects corresponding to form elements (such as checkbox, radio, and text objects) in source order. 446 | 447 |

    Syntax

    448 |
    449 | 1. formName.elements[index]
    450 | 2. formName.elements.length
    451 | 
    452 |

    formName is either the name of a form or an element in the forms array. 453 |
    index is an integer representing an object on a form. 454 | 455 | 456 |

    Property of

    457 |
  • form 458 | 459 | 460 |

    Description

    461 |

    You can reference a form's elements in your code by using the elements array. This array contains an entry for each object (button, checkbox, hidden, password, radio, reset, select, submit, text, or textarea object) in a form in source order. For example, if a form has a text field and two checkboxes, these elements are reflected as formName.elements[0], formName.elements[1], and formName.elements[2]. 462 | 463 |

    Although you can also reference a form's elements by using the element's name (from the NAME attribute), the elements array provides a way to reference form objects programatically without using their names. For example, if the first object on the userInfo form is the userName text object, you can evaluate it in either of the following ways: 464 |

    465 | userInfo.userName.value
    466 | userInfo.elements[0].value
    467 | 
    468 | 469 |

    To obtain the number of elements on a form, use the length property: formName.elements.length. Each radio button in a radio object appears as a separate element in the elements array. 470 | 471 |

    Elements in the elements array are read-only. For example, the statement formName.elements[0]="music" has no effect. 472 | 473 |

    The value of each element in the elements array is the full HTML statement for the object. 474 | 475 | 476 |

    Properties

    477 |
  • length reflects the number of elements on a form 478 | 479 | 480 |

    Examples

    481 |

    See the examples for the name property. 482 | 483 | 484 |

    See also

    485 |
  • form object 486 | 487 | 488 | 489 |
    490 |

    elements property

    491 |

    An array of objects corresponding to form elements (such as checkbox, radio, and text objects) in source order. See elements array. 492 | 493 | 494 |


    495 |

    encoding property

    496 |

    497 | A string specifying the MIME encoding of the form. 498 | 499 |

    Syntax

    500 |
    formName.encoding
    501 |

    formName is either the name of a form or an element in the forms array. 502 | 503 |

    Property of

    504 |

    form 505 | 506 |

    Description

    507 |

    The encoding property initially reflects the ENCTYPE attribute of the <FORM> tag; however, setting encoding overrides the ENCTYPE attribute. 508 | 509 |

    You can set the encoding property at any time. 510 | 511 |

    Certain values of the encoding property may require specific values for other form properties. See RFC 1867 for more information. 512 | 513 |

    Examples

    514 |

    The following function returns the value of the musicForm encoding property: 515 |

    516 | function getEncoding() {
    517 |    return document.musicForm.encoding
    518 | }
    519 | 
    520 | 521 |

    See also

    522 |
  • action, method, target properties 523 | 524 | 525 |
    526 |

    escape function

    527 |

    528 | Returns the ASCII encoding of an argument in the ISO Latin-1 character set. 529 | 530 |

    Syntax

    531 |
    escape("string")
    532 |

    string is a non-alphanumeric string in the ISO Latin-1 character set, or a property of an existing object. 533 | 534 |

    Description

    535 |

    The escape function is not a method associated with any object, but is part of the language itself. 536 | 537 |

    The value returned by the escape function is a string of the form "%xx", where xx is the ASCII encoding of a character in the argument. If you pass the escape function an alphanumeric character, the escape function returns the same character. 538 | 539 | 540 |

    Examples

    541 |

    The following example returns "%26" 542 |

    543 | escape("&")
    544 | 
    545 | 546 |

    The following example returns "%21%23" 547 |

    548 | escape("!#")
    549 | 
    550 | 551 |

    See also

    552 |
  • unescape function 553 | 554 | 555 |
    556 |

    eval function

    557 |

    558 | The eval function evaluates a string and returns a value. 559 | 560 |

    Syntax

    561 |
    eval(string)
    562 | string is any string representing a JavaScript expression, statement, or sequence of statements. The expression can include variables and properties of existing objects. 563 | 564 |

    Description

    565 |

    The eval function is a built-in JavaScript function. It is not a method associated with any object, but is part of the language itself. 566 | 567 |

    The argument of the eval function is a string. Do not call eval to evaluate an arithmetic expression. JavaScript evaluates arithmetic expressions automatically. If the argument represents an expression, eval evaluates the expression. If the argument represents one or more JavaScript statements, eval performs the statements. 568 | 569 |

    If you construct an arithmetic expression as a string, you can use eval to evaluate it at a later time. For example, suppose you have a variable x. You can postpone evaluation of an expression involving x by assigning the string value of the expression, say "3 * x + 2", to a variable, and then calling eval at a later point in your script. 570 | 571 |

    Examples

    572 |

    Example 1. Both of the write statements below display 42. The first evaluates the string "x + y + 1", and the second evaluates the string "42". 573 | 574 |

    575 | var x = 2
    576 | var y = 39
    577 | var z = "42"
    578 | document.write(eval("x + y + 1"), "<BR>") 
    579 | document.write(eval(z), "<BR>")
    580 | 
    581 | 582 |

    Example 2. In the following example, the getFieldName(n) function returns the name of the nth form element as a string. The first statement assigns the string value of the third form element to the variable field. The second statement uses eval to display the value of the form element. 583 |

    584 | var field = getFieldName(3) 
    585 | document.write("The field named ", field, " has value of ", eval(field + ".value"))
    586 | 
    587 | 588 |

    Example 3. The following example uses eval to evaluate the string str. This string consists of JavaScript statements that opens an alert dialog box and assigns z a value of 42 if x is five, and assigns zero to z otherwise. When the second statement is executed, eval will cause these statements to be performed, and it will also evaluate the set of statements and return the value that is assigned to z. 589 | 590 |

    591 | var str = "if (x == 5) {alert('z is 42'); z = 42;} else z = 0; "
    592 | document.write("<P>z is ", eval(str))
    593 | 
    594 | 595 |

    Example 4. In the following example, the setValue() function uses eval to assign the value of the variable newValue to the text field textObject. 596 |

    597 | function setValue (textObject, newValue) {
    598 |   eval ("document.forms[0]." + textObject + ".value") = newValue
    599 | }
    600 | 
    601 | 602 | 603 |
    604 |

    exp method

    605 |

    606 | Returns enumber, where number is the argument, and e is Euler's constant, the base of the natural logarithms. 607 | 608 |

    Syntax

    609 |
    Math.exp(number)
    610 | number is any numeric expression or a property of an existing object. 611 | 612 |

    Method of

    613 |

    Math 614 | 615 |

    Examples

    616 |
    617 | //Displays the value 2.718281828459045
    618 | document.write("The value of e<SUP>1</SUP> is " + Math.exp(1))
    619 | 
    620 | 621 |

    See also

    622 |
  • log, pow methods 623 | 624 |
    625 | 626 | 629 |

    630 | 631 | -------------------------------------------------------------------------------- /js-1.0/ref_r-r.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

    radio object

    5 |

    A set of radio buttons on an HTML form. A set of radio buttons lets the user choose one item from a list. 6 | 7 | 8 |

    Syntax

    9 |

    To define a set of radio buttons, use standard HTML syntax with the addition of the onClick event handler: 10 |

     11 | <INPUT
     12 |    TYPE="radio"
     13 |    NAME="radioName"
     14 |    VALUE="buttonValue"
     15 |    [CHECKED]
     16 |    [onClick="handlerText"]>
     17 |    textToDisplay
     18 | 
    19 | NAME="radioName" specifies the name of the radio object. All radio buttons in a group have the same NAME attribute. You can access this value using the name property. 20 |
    VALUE="buttonValue" specifies a value that is returned to the server when the radio button is selected and the form is submitted. This defaults to "on". You can access this value using the value property. 21 |
    CHECKED specifies that the radio button is selected. You can access this value using the defaultChecked property. 22 |
    textToDisplay specifies the label to display beside the radio button. 23 | 24 |

    To use a radio button's properties and methods: 25 |

     26 | 1. radioName[index1].propertyName
     27 | 2. radioName[index1].methodName(parameters)
     28 | 3. formName.elements[index2].propertyName
     29 | 4. formName.elements[index2].methodName(parameters)
     30 | 
    31 | radioName is the value of the NAME attribute of a radio object. 32 |
    index1 is an integer representing a radio button in a radio object. 33 |
    formName is either the value of the NAME attribute of a form object or an element in the forms array. 34 |
    index2 is an integer representing a radio button on a form. The elements array contains an entry for each radio button in a radio object. 35 |
    propertyName is one of the properties listed below. 36 |
    methodName is one of the methods listed below. 37 | 38 | 39 |

    Property of

    40 |
  • form 41 | 42 | 43 |

    Description

    44 |

    A radio object on a form looks as follows: 45 |

    46 |

    R&B 47 |
    Jazz 48 |
    Soul 49 |

    50 |

    A radio object is a form element and must be defined within a <FORM> tag. 51 | 52 |

    All radio buttons in a radio button group use the same name property. To access the individual radio buttons in your code, 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.forms[0].radioName[0] is the first, document.forms[0].radioName[1] is the second, etc. 53 | 54 | 55 |

    Properties

    56 |
  • checked lets you programatically select a radio button 57 |
  • defaultChecked reflects the CHECKED attribute 58 |
  • length reflects the number of radio buttons in a radio object 59 |
  • name reflects the NAME attribute 60 |
  • value reflects the VALUE attribute 61 | 62 | 63 |

    Methods

    64 |
  • click 65 | 66 | 67 |

    Event handlers

    68 |
  • onClick 69 | 70 | 71 |

    Examples

    72 |

    Example 1. The following example defines a radio button group to choose among three music catalogs. Each radio button is given the same name, NAME="musicChoice", forming a group of buttons for which only one choice can be selected. 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. The onClick event handler sets the catalog name input field when the user clicks a radio button. 73 |

    74 | <INPUT TYPE="text" NAME="catalog" SIZE="20"> 75 | <INPUT TYPE="radio" NAME="musicChoice" VALUE="soul-and-r&b" 76 | onClick="musicForm.catalog.value = 'soul-and-r&b'"> Soul and R&B 77 | <INPUT TYPE="radio" NAME="musicChoice" VALUE="jazz" 78 | onClick="musicForm.catalog.value = 'jazz'"> Jazz 79 | <INPUT TYPE="radio" NAME="musicChoice" VALUE="classical" 80 | onClick="musicForm.catalog.value = 'classical'"> Classical 81 | 82 | 83 |

    Example 2. The following example contains a form with three text boxes and three radio buttons. The radio buttons let the user choose whether the text fields are converted to upper case or lower case, 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. The radio buttons for upper case and lower case have onClick event handlers that convert all fields when the user clicks the radio button. 84 |

    85 | <HTML> 86 | <HEAD> 87 | <TITLE>Radio object example</TITLE> 88 | </HEAD> 89 | <SCRIPT> 90 | function convertField(field) { 91 | if (document.form1.conversion[0].checked) { 92 | field.value = field.value.toUpperCase()} 93 | else { 94 | if (document.form1.conversion[1].checked) { 95 | field.value = field.value.toLowerCase()} 96 | } 97 | } 98 | function convertAllFields(caseChange) { 99 | if (caseChange=="upper") { 100 | document.form1.lastName.value = document.form1.lastName.value.toUpperCase() 101 | document.form1.firstName.value = document.form1.firstName.value.toUpperCase() 102 | document.form1.cityName.value = document.form1.cityName.value.toUpperCase()} 103 | else { 104 | document.form1.lastName.value = document.form1.lastName.value.toLowerCase() 105 | document.form1.firstName.value = document.form1.firstName.value.toLowerCase() 106 | document.form1.cityName.value = document.form1.cityName.value.toLowerCase() 107 | } 108 | } 109 | </SCRIPT> 110 | <BODY> 111 | <FORM NAME="form1"> 112 | <B>Last name:</B> 113 | <INPUT TYPE="text" NAME="lastName" SIZE=20 onChange="convertField(this)"> 114 | <BR><B>First name:</B> 115 | <INPUT TYPE="text" NAME="firstName" SIZE=20 onChange="convertField(this)"> 116 | <BR><B>City:</B> 117 | <INPUT TYPE="text" NAME="cityName" SIZE=20 onChange="convertField(this)"> 118 | <P><B>Convert values to:</B> 119 | <BR><INPUT TYPE="radio" NAME="conversion" VALUE="upper" 120 | onClick="if (this.checked) {convertAllFields('upper')}"> Upper case 121 | <BR><INPUT TYPE="radio" NAME="conversion" VALUE="lower" 122 | onClick="if (this.checked) {convertAllFields('lower')}"> Lower case 123 | <BR><INPUT TYPE="radio" NAME="conversion" VALUE="noChange"> No conversion 124 | </FORM> 125 | </BODY> 126 | </HTML> 127 | 128 | 129 |

    See also the example for the link object. 130 | 131 | 132 |

    See also

    133 |
  • checkbox, form, and select objects 134 | 135 | 136 | 137 |
    138 |

    random method

    139 |

    140 | Returns a pseudo-random number between zero and one. This method is available on Unix platforms only. 141 | 142 |

    Syntax

    143 |

    Math.random() 144 | 145 |

    Method of

    146 |

    Math 147 | 148 |

    Examples

    149 |
    150 | //Displays a random number between 0 and 1
    151 | document.write("The random number is " + Math.random())
    152 | 
    153 | 154 | 155 |
    156 |

    referrer property

    157 |

    158 | Specifies the URL of the calling document when a user clicks a link. 159 | 160 |

    Syntax

    161 |
    document.referrer
    162 | 163 |

    Property of

    164 |

    document 165 | 166 |

    Description

    167 |

    When a user navigates to a destination document by clicking a link object on a source document, the referrer property contains the URL of the source document. Evaluate the referrer property from the destination document. 168 | 169 |

    referrer is a read-only property. 170 | 171 |

    Examples

    172 |

    In the following example, the getReferrer() function is called from the destination document. It returns the URL of the source document. 173 |

    174 | function getReferrer() {
    175 |    return document.referrer
    176 | }
    177 | 
    178 | 179 | 180 |
    181 |

    reset object

    182 |

    A reset button on an HTML form. A reset button resets all elements in a form to their defaults. 183 | 184 | 185 |

    Syntax

    186 |

    To define a reset button, use standard HTML syntax with the addition of the onClick event handler: 187 |

    188 | <INPUT
    189 |    TYPE="reset"
    190 |    NAME="resetName"
    191 |    VALUE="buttonText"
    192 |    [onClick="handlerText"]>
    193 | 
    194 | NAME="resetName" specifies the name of the reset object. You can access this value using the name property. 195 |
    VALUE="buttonText" specifies the text to display on the button face. You can access this value using the value property. 196 | 197 |

    To use a reset object's properties and methods: 198 |

    199 | 1. resetName.propertyName
    200 | 2. resetName.methodName(parameters)
    201 | 3. formName.elements[index].propertyName
    202 | 4. formName.elements[index].methodName(parameters)
    203 | 
    204 | resetName is the value of the NAME attribute of a reset object. 205 |
    formName is either the value of the NAME attribute of a form object or an element in the forms array. 206 |
    index is an integer representing a reset object on a form. 207 |
    propertyName is one of the properties listed below. 208 |
    methodName is one of the methods listed below. 209 | 210 | 211 |

    Property of

    212 |
  • form 213 | 214 | 215 |

    Description

    216 |

    A reset object on a form looks as follows: 217 |

    218 |

    219 |

    220 |

    A reset object is a form element and must be defined within a <FORM> tag. 221 | 222 |

    The reset button's onClick event handler cannot prevent a form from being reset; once the button is clicked, the reset cannot be canceled. 223 | 224 | 225 |

    Properties

    226 |
  • name reflects the NAME attribute 227 |
  • value reflects the VALUE attribute 228 | 229 | 230 |

    Methods

    231 |
  • click 232 | 233 | 234 |

    Event handlers

    235 |
  • onClick 236 | 237 | 238 |

    Examples

    239 |

    Example 1. 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. If the user types a state abbreviation in the text object and then clicks the Clear Form button, the original value of "CA" is restored. 240 |

    241 | <B>State: </B><INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2"> 242 | <P><INPUT TYPE="reset" VALUE="Clear Form"> 243 | 244 | 245 |

    Example 2. The following example displays two text objects, a select object, and three radio buttons; 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, the original values are restored. 246 |

    247 | <HTML> 248 | <HEAD> 249 | <TITLE>Reset object example</TITLE> 250 | </HEAD> 251 | <BODY> 252 | <FORM NAME="form1"> 253 | <BR><B>City: </B><INPUT TYPE="text" NAME="city" VALUE="Santa Cruz" SIZE="20"> 254 | <B>State: </B><INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2"> 255 | <P><SELECT NAME="colorChoice"> 256 | <OPTION SELECTED> Blue 257 | <OPTION> Yellow 258 | <OPTION> Green 259 | <OPTION> Red 260 | </SELECT> 261 | <P><INPUT TYPE="radio" NAME="musicChoice" VALUE="soul-and-r&b" 262 | CHECKED> Soul and R&B 263 | <BR><INPUT TYPE="radio" NAME="musicChoice" VALUE="jazz"> 264 | Jazz 265 | <BR><INPUT TYPE="radio" NAME="musicChoice" VALUE="classical"> 266 | Classical 267 | <P><INPUT TYPE="reset" VALUE="Defaults" NAME="reset1"> 268 | </FORM> 269 | </BODY> 270 | </HTML> 271 | 272 | 273 | 274 |

    See also

    275 |
  • button, form, and submit objects 276 | 277 | 278 | 279 |
    280 |

    round method

    281 |

    282 | Returns the value of a number rounded to the nearest integer. 283 | 284 |

    Syntax

    285 |
    Math.round(number)
    286 | number is any numeric expression or a property of an existing object. 287 | 288 |

    Method of

    289 |

    Math 290 | 291 |

    Description

    292 |

    If the fractional portion of number is .5 or greater, the argument is rounded to the next highest integer. If the fractional portion of number is less than .5, the argument is rounded to the next lowest integer. 293 | 294 |

    Examples

    295 |
    296 | //Displays the value 20
    297 | document.write("The rounded value is " + Math.round(20.49))
    298 | 
    299 | //Displays the value 21
    300 | document.write("<P>The rounded value is " + Math.round(20.5))
    301 | 
    302 | //Displays the value -20
    303 | document.write("<P>The rounded value is " + Math.round(-20.5))
    304 | 
    305 | //Displays the value -21
    306 | document.write("<P>The rounded value is " + Math.round(-20.51))
    307 | 
    308 | 309 | 310 |
    311 | 312 | 315 |

    316 | 317 | -------------------------------------------------------------------------------- /js-1.0/script.html: -------------------------------------------------------------------------------- 1 | 2 | Navigator Scripting 3 | 4 | 5 | 6 | 7 |

    Navigator Scripting

    8 | 9 | 14 |

    Using JavaScript in HTML

    15 | 16 |

    17 | JavaScript can be embedded in an HTML document in two ways: 18 |

      19 |
    • As statements and functions using the SCRIPT tag. 20 |
    • As event handlers using HTML tags. 21 |
    22 | 23 |

    The SCRIPT tag

    24 | A script embedded in HTML with the SCRIPT tag uses the format: 25 | 26 | <SCRIPT> 27 | JavaScript statements... 28 | </SCRIPT> 29 | 30 | 31 |

    32 | The optional LANGUAGE attribute specifies the scripting language as 33 | follows: 34 |

    35 | <SCRIPT LANGUAGE="JavaScript"> 36 | JavaScript statements... 37 | </SCRIPT> 38 | 39 | 40 |

    41 | The HMTL tag, <SCRIPT>, and its closing counterpart, </SCRIPT> 42 | can enclose any number of JavaScript statements in a document. 43 |

    44 | JavaScript is case sensitive. 45 |


    46 | 47 |

    48 | Example 1: a simple script. 49 |

    50 |

    51 | <HTML> 52 | <HEAD> 53 | <SCRIPT LANGUAGE="JavaScript"> 54 | document.write("Hello net.") 55 | </SCRIPT> 56 | </HEAD> 57 | <BODY> 58 | That's all, folks. 59 | </BODY> 60 | </HTML> 61 | 62 |

    63 | Example 1 page display. 64 |

    65 | Hello net. That's all folks. 66 |


    67 | 68 |

    Code Hiding

    69 | Scripts can be placed inside comment fields to ensure that your 70 | JavaScript code is not displayed by old browsers that do not 71 | recognize JavaScript. The entire script is encased by HTML comment 72 | tags: 73 | 74 | <!-- Begin to hide script contents from old browsers. 75 | // End the hiding here. --> 76 | 77 | 78 |

    Defining and Calling Functions

    79 |

    80 | Scripts placed within SCRIPT tags are evaluated after the page loads. 81 | Functions are stored, but not executed. Functions are executed by 82 | events in the page. 83 |

    84 | It's important to understand the difference between defining a 85 | function and calling the function. Defining the function simply 86 | names the function and specifies what to do when the function is 87 | called. Calling the function actually performs the specified actions 88 | with the indicated parameters. 89 |


    90 | 91 |

    92 | Example 2: a script with a function and comments. 93 |

    94 | <HEAD> 95 | <SCRIPT LANGUAGE="JavaScript"> 96 | <!-- to hide script contents from old browsers 97 | function square(i) { 98 | document.write("The call passed ", i ," to the function.","&lt;BR&gt;") 99 | return i * i 100 | } 101 | document.write("The function returned ",square(5),".") 102 | // end hiding contents from old browsers --> 103 | </SCRIPT> 104 | </HEAD> 105 | <BODY> 106 | <BR> 107 | All done. 108 | </BODY> 109 | 110 | 111 |

    112 | Example 2 page display. 113 |

    114 | We passed 5 to the function. 115 |
    116 | The function returned 25. 117 |
    118 | All done. 119 |


    120 | 121 |

    The HEAD tag

    122 | Generally, you should define the functions for a page in the HEAD 123 | portion of a document. Since the HEAD is loaded first, this practice 124 | guarantees that functions are loaded before the user has a chance to 125 | do anything that might call a function. 126 |
    127 | 128 |

    129 | Example 3: a script with two functions. 130 |

    131 | <HEAD> 132 | <SCRIPT> 133 | <!--- hide script from old browsers 134 | function bar() { 135 | document.write("<HR ALIGN='left' WIDTH=25%>") 136 | } 137 | function output(head, level, string) { 138 | document.write("<H" + level + ">" + head + "</H" + level + "><P>" + string) 139 | } 140 | // end hiding from old browsers --> 141 | </SCRIPT> 142 | </HEAD> 143 | 144 | <BODY> 145 | <SCRIPT> 146 | <!--- hide script from old browsers 147 | document.write(bar(),output("Make Me Big",3,"Make me ordinary.")) 148 | // end hiding from old browsers --> 149 | </SCRIPT> 150 | <P> 151 | Thanks. 152 | </BODY> 153 | 154 | 155 |

    156 | Example 3 results. 157 | 168 |

    169 | Thanks. 170 |


    171 | 172 |

    Quotes

    173 | Use single quotes (') to delimit string literals so that scripts can 174 | distinguish the literal from attribute values enclosed in double 175 | quotes. In the previous example, function bar contains the literal 176 | 'left' within a double-quoted attribute value. Here's another 177 | example: 178 | 179 | <INPUT TYPE="button" VALUE="Press Me" onClick="myfunc('astring')"> 180 | 181 | 182 |
    183 | 184 |

    Scripting Event Handlers

    185 |

    186 | 187 | JavaScript applications in the Navigator are largely event-driven. 188 | Events are actions that occur, usually as a result of something the user does. 189 | For example, a button click is an event, as is giving focus to a form 190 | element. There is a specific set of events that Navigator recognizes. 191 | You can define Event handlers, scripts that are automatically executed 192 | when an event occurs. 193 | 194 |

    195 | Event handlers are embedded in documents as attributes of HTML tags to which you 196 | assign JavaScript code to execute. 197 | The general syntax is 198 |

    199 | <TAG eventHandler="JavaScript Code"> 200 | 201 | where TAG is some HTML tag and eventHandler is the name of the event handler. 202 | 203 |

    204 | For example, suppose you have created a JavaScript function called 205 | compute. You can cause Navigator to perform this function when the user clicks on a 206 | button by assigning the function call to the button's onClick event handler: 207 | 208 |

    209 | <INPUT TYPE="button" VALUE="Calculate" onClick="compute(this.form)"> 210 | 211 |

    212 | You can put any JavaScript statements inside the quotes following onClick. 213 | These statements get executed when the user clicks on the button. 214 | If you want to include more than one statement, separate statements with a semicolon (;). 215 |

    216 | In general, it is a good idea to define functions for your event handlers because: 217 |

      218 |
    • it makes your code modular-you can use the same function as an event handler for 219 | many different items. 220 |
    • it makes your code easier to read. 221 |
    222 | 223 |

    224 | Notice in this example the use of this.form to refer to the current form. 225 | The keyword 226 | this refers to the current object-in the above example, 227 | the button object. The construct this.form then refers to the form 228 | containing the button. In the above example, the onClick event handler is a 229 | call to the compute() function, with this.form, the current form, 230 | as the parameter to the function. 231 | 232 |

    233 | Events apply to HTML tags as follows: 234 |

      235 |
    • Focus, Blur, Change events: text fields, textareas, and selections 236 |
    • Click events: buttons, radio buttons, checkboxes, submit 237 | buttons, reset buttons, links 238 |
    • Select events: text fields, textareas 239 |
    • MouseOver event: links 240 |
    241 |

    242 | If an event applies to an HTML tag, then you can define an event handler for it. 243 | In general, an event handler has the name of the event, preceded by "on." 244 | For example, the event handler for the Focus event is onFocus. 245 |

    246 | Many objects also have methods that emulate events. For example, button has a click 247 | method that emulates the button being clicked. 248 | Note: The event-emulation methods do not trigger event-handlers. So, for example, 249 | the click method does not trigger an onClick event-handler. 250 | However, you can always call an event-handler directly (for example, you can call 251 | onClick explicitly in a script). 252 | 253 |

    254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 |
    EventOccurs when...Event Handler
    blurUser removes input focus from form elementonBlur
    clickUser clicks on form element or linkonClick
    changeUser changes value of text, textarea, or select elementonChange
    focusUser gives form element input focusonFocus
    loadUser loads the page in the NavigatoronLoad
    mouseoverUser moves mouse pointer over a link or anchoronMouseOver
    selectUser selects form element's input fieldonSelect
    submitUser submits a formonSubmit
    unloadUser exits the pageonUnload
    315 |


    316 | 317 |

    318 | Example 4: a script with a form and an event handler attribute. 319 | 320 | 321 |

    322 | <HEAD> 323 | <SCRIPT LANGUAGE="JavaScript"> 324 | function compute(form) { 325 | if (confirm("Are you sure?")) 326 | form.result.value = eval(form.expr.value) 327 | else 328 | alert("Please come back again.") 329 | } 330 | </SCRIPT> 331 | </HEAD> 332 | 333 | <BODY> 334 | <FORM> 335 | Enter an expression: 336 | <INPUT TYPE="text" NAME="expr" SIZE=15 > 337 | <INPUT TYPE="button" VALUE="Calculate" ONCLICK="compute(this.form)"> 338 | <BR> 339 | Result: 340 | <INPUT TYPE="text" NAME="result" SIZE=15 > 341 | <BR> 342 | </FORM> 343 | </BODY> 344 | 345 | 346 | 347 |

    348 | Example 4 page display. 349 |

    350 | 360 | 361 |

    362 | Enter an expression: 363 | 364 | 365 |
    366 | Result: 367 | 368 |
    369 |
    370 |
    371 | 372 |

    373 | Example 5: a script with a form and event handler attribute within a BODY tag. 374 | 375 | 376 |

    377 | <HEAD> 378 | <SCRIPT LANGUAGE="JavaScript"> 379 | <!--- hide script from old browsers 380 | function checkNum(str, min, max) { 381 | if (str == "") { 382 | alert("Enter a number in the field, please.") 383 | return false 384 | } 385 | for (var i = 0; i < str.length; i++) { 386 | var ch = str.substring(i, i + 1) 387 | if (ch < "0" || ch > "9") { 388 | alert("Try a number, please.") 389 | return false 390 | } 391 | } 392 | 393 | var val = parseInt(str, 10) 394 | if ((val < min) || (val > max)) { 395 | alert("Try a number from 1 to 10.") 396 | return false 397 | } 398 | return true 399 | } 400 | 401 | function thanks() { 402 | alert("Thanks for your input.") 403 | } 404 | // end hiding from old browsers --> 405 | </SCRIPT> 406 | </HEAD> 407 | 408 | <BODY> 409 | <FORM NAME="ex5"> 410 | Please enter a small number: 411 | <INPUT NAME="num" 412 | onChange="if (!checkNum(this.value, 1, 10)) 413 | {this.focus();this.select();} else {thanks()}"> 414 | </FORM> 415 | </BODY> 416 | 417 | 418 | 419 |

    420 | Example 5 page display. 421 |

    422 | Enter a number in the field and then click your mouse anywhere OUTSIDE of the field. 423 | Depending on what you enter, you will be prompted to enter another number, or thanked. 424 | 425 | 451 | 452 |

    453 | Please enter a small number: 454 | 457 |
    458 | 459 |
    460 | 461 |

    Tips and Techniques

    462 |

    463 | This section describes various useful scripting techniques. 464 |

    465 |

    Updating Pages

    466 |

    467 | JavaScript in Navigator generates its results from the top of the page down. 468 | Once something has been formatted, you can't change it without reloading the page. 469 | Currently, you cannot update a particular part of a page without updating the entire page. 470 | However, you can update a "sub-window" in a frame separately. 471 |

    472 |

    Printing

    473 |

    474 | You cannot currently print output created with JavaScript. 475 | For example, if you had the following in a page: 476 |

    477 | <P>This is some text. 478 | <SCRIPT>document.write("<P>And some generated text")</SCRIPT> 479 | 480 | And you printed it, you would get only "This is some text", 481 | even though you would see both lines on-screen. 482 |

    483 |

    Using Quotes

    484 |

    485 | Be sure to alternate double quotes with single quotes. 486 | Since event handlers in HTML must be enclosed in quotes, you must use single 487 | quotes to delimit arguments. For example 488 | 489 |

    490 | <FORM NAME="myform"> 491 | <INPUT TYPE="button" NAME="Button1" VALUE="Open Sesame!" 492 | onClick="window.open('stmtsov.html', 'newWin', 'toolbar=no,directories=no')"> 493 | </FORM> 494 | 495 |

    496 | Alternatively, you can escape quotes by preceding them by a backslash (\). 497 | 498 |

    Defining Functions

    499 |

    500 | It is always a good idea to define all of your functions in the HEAD of your HTML page. 501 | This way, all functions will be defined before any content is displayed. 502 | Otherwise, the user might perform some action while the page is still loading that triggers 503 | an event handler and calls an undefined function, leading to an error. 504 | 505 |

    Creating Arrays

    506 |

    507 | An array is an ordered set of values that you reference through an array name and an index. 508 | For example, you could have an array called emp, that contains employees' names 509 | indexed by their employee number. So emp[1] would be employee number one, emp[2] 510 | employee number two, and so on. 511 | 512 |

    513 | JavaScript does not have an explicit array data type, but because of the intimate relationship 514 | between arrays and object properties (see JavaScript Object Model), 515 | it is easy to create arrays in JavaScript. 516 | You can define an array object type, as follows: 517 |

    518 | function MakeArray(n) {
    519 |    this.length = n;
    520 |    for (var i = 1; i <= n; i++) { 
    521 |      this[i] = 0 }
    522 |      return this
    523 |      }
    524 | }
    525 | 
    526 |

    527 | This defines an array such that the first property, length, (with index of zero), 528 | represents the number of elements in the array. 529 | The remaining properties have an integer index of one or greater, and are initialized to zero. 530 |

    531 | You can then create an array by a call to new with the array name, 532 | specifying the number of elements it has. For example: 533 |

    534 | emp = new MakeArray(20);
    535 | 
    536 |

    537 | This creates an array called emp with 20 elements, and initializes the elements to zero. 538 | 539 |

    Populating an Array

    540 |

    541 | You can populate an array by simply assigning values to its elements. For example: 542 |

    543 | emp[1] = "Casey Jones"
    544 | emp[2] = "Phil Lesh"
    545 | emp[3] = "August West"
    546 | 
    547 | and so on. 548 | 549 |

    550 | You can also create arrays of objects. For example, suppose you define an object type 551 | named Employees, as follows: 552 | 553 |

    554 | function Employee(empno, name, dept) {
    555 |    this.empno = empno;
    556 |    this.name = name;
    557 |    this.dept = dept;
    558 | }
    559 | 
    560 |

    561 | Then the following statements define an array of these objects: 562 | 563 |

    564 | emp = new MakeArray(3)
    565 | emp[1] = new Employee(1, "Casey Jones", "Engineering")
    566 | emp[2] = new Employee(2, "Phil Lesh", "Music")
    567 | emp[3] = new Employee(3, "August West", "Admin")
    568 | 
    569 |

    570 | Then you can easily display the objects in this array using the show_props function 571 | (defined in the section on the JavaScript Object Model) as follows: 572 |

    573 | for (var n =1; n <= 3; n++) {
    574 |    document.write(show_props(emp[n], "emp") + "
    "); 575 | } 576 |
    577 |

    578 | 579 | 580 | -------------------------------------------------------------------------------- /js-1.0/stmts.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

    5 |

    Statements

    6 | 7 |

    JavaScript 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. 8 | 9 |

    Syntax conventions: All keywords in syntax statements are in bold. Words in italics represent user-defined 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 {}. 10 | 11 |

    The following statements are available in JavaScript: 12 | 13 | 14 | 23 | 31 | 32 |
    15 |
  • break 16 |
  • comment 17 |
  • continue 18 |
  • for 19 |
  • for...in 20 |
  • function 21 |
  • if...else 22 |
  • 24 |
  • new 25 |
  • return 26 |
  • this 27 |
  • var 28 |
  • while 29 |
  • with 30 |
  • 33 | 34 |

    NOTE: new and this are not really statements, but are included in this section for convenience. 35 | 36 | 37 | 38 |


    39 |

    break

    40 |

    A statement that terminates the current while or for loop and transfers program control to the statement following the terminated loop. 41 | 42 | 43 |

    Syntax

    44 |
     45 | break
     46 | 
    47 | 48 | 49 |

    Examples

    50 |

    The following function has a break statement that terminates the while loop when i is 3, and then returns the value 3 * x. 51 |

    52 | function testBreak(x) { 53 | var i = 0 54 | while (i < 6) { 55 | if (i == 3) 56 | break 57 | i++ 58 | } 59 | return i*x 60 | } 61 | 62 | 63 | 64 | 65 |
    66 |

    comment

    67 |

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

      69 |
    • Comments on a single line are preceded by a double-slash (//). 70 |
    • Comments that span multiple lines are preceded by a /* and followed by a */. 71 |
    72 | 73 | 74 |

    Syntax

    75 |
     76 | 1. // comment text
     77 | 2. /* multiple line comment text */
     78 | 
    79 | 80 | 81 |

    Examples

    82 | 83 | // This is a single-line comment. 84 | /* This is a multiple-line comment. It can be of any length, and 85 | you can put whatever you want here. */ 86 | 87 | 88 | 89 | 90 |
    91 |

    continue

    92 |

    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, 93 |

      94 |
    • In a while loop, it jumps back to the condition. 95 |
    • In a for loop, it jumps to the update expression. 96 |
    97 | 98 | 99 |

    Syntax

    100 |
    101 | continue
    102 | 103 | 104 | 105 |

    Examples

    106 |

    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. 107 |

    108 | i = 0 109 | n = 0 110 | while (i < 5) { 111 | i++ 112 | if (i == 3) 113 | continue 114 | n += i 115 | } 116 | 117 | 118 | 119 | 120 |
    121 |

    for

    122 |

    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. 123 | 124 | 125 |

    Syntax

    126 |
    127 | for ([initial-expression;] [condition;] [increment-expression]) {
    128 |    statements
    129 | }
    130 | 
    131 | 132 | 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. 133 |

    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. 134 |

    increment-expression is generally used to update or increment the counter variable. 135 |

    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. 136 | 137 | 138 |

    Examples

    139 |

    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. 140 |

    141 | for (var i = 0; i < 9; i++) { 142 | n += i 143 | myfunc(n) 144 | } 145 | 146 | 147 | 148 | 149 |
    150 |

    for...in

    151 |

    A statement that iterates a specified variable over all the properties of an object. For each distinct property, JavaScript executes the specified statements. 152 | 153 | 154 |

    Syntax

    155 |
    156 | for (variable in object) {
    157 |    statements }
    158 | 
    159 | 160 | variable is the variable to iterate over every property. 161 |

    object is the object for which the properties are iterated. 162 |

    statements specifies the statements to execute for each property. 163 | 164 |

    Examples

    165 |

    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. 166 |

    167 | function dump_props(obj, obj_name) { 168 | var result = "" 169 | for (var i in obj) { 170 | result += obj_name + "." + i + " = " + obj[i] + "<BR>" 171 | } 172 | result += "<HR>" 173 | return result 174 | } 175 | 176 | 177 | 178 | 179 |
    180 |

    function

    181 |

    A statement that declares a JavaScript function name with the specified parameters param. Acceptable parameters include strings, numbers, and objects. 182 | 183 |

    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. 184 | 185 |

    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. 186 | 187 |

    Syntax

    188 |
    189 | function name([param] [, param] [..., param]) {
    190 |    statements }
    191 | 
    192 | 193 | 194 |

    Examples

    195 | 196 | //This function returns the total dollar amount of sales, when 197 | //given the number of units sold of products a, b, and c. 198 | function calc_sales(units_a, units_b, units_c) { 199 | return units_a*79 + units_b*129 + units_c*699 200 | } 201 | 202 | 203 | 204 | 205 |
    206 |

    if...else

    207 |

    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. 208 | 209 |

    Syntax

    210 |
    211 | if (condition) {
    212 |    statements1 }
    213 | [else {
    214 |    statements2}]
    215 | 
    216 | 217 |

    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. 218 |

    statements1 and statements2 can be any JavaScript statements, including further nested if statements. Multiple statements must be enclosed in braces. 219 | 220 |

    Examples

    221 | 222 | if ( cipher_char == from_char ) { 223 | result = result + to_char 224 | x++ } 225 | else 226 | result = result + clear_char 227 | 228 | 229 | 230 | 231 |
    232 |

    new

    233 |

    An operator that lets you create an instance of a user-defined object type. 234 | 235 |

    Creating an object type requires two steps: 236 |

      237 |
    1. Define the object type by writing a function. 238 |
    2. Create an instance of the object with new. 239 |
    240 |

    To define an object type, create a function for the object type that specifies its name, properties, and methods. An object can have a property that is itself another object. See the examples below. 241 | 242 |

    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 must add the property to the definition of the car object type. 243 | 244 | 245 |

    Syntax

    246 |
    247 | objectName = new objectType ( param1 [,param2] ...[,paramN] )
    248 | 
    249 | 250 | objectName is the name of the new object instance. 251 |
    objectType is the object type. It must be a function that defines an object type. 252 |
    param1...paramN are the property values for the object. These properties are parameters defined for the objectType function. 253 | 254 | 255 |

    Examples

    256 |

    Example 1: object type and object instance.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: 257 |

    258 | function car(make, model, year) { 259 | this.make = make 260 | this.model = model 261 | this.year = year 262 | } 263 | 264 | 265 |

    Now you can create an object called mycar as follows: 266 |

    267 | mycar = new car("Eagle", "Talon TSi", 1993) 268 | 269 | 270 |

    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. 271 | 272 |

    You can create any number of car objects by calls to new. For example, 273 |

    274 | kenscar = new car("Nissan", "300ZX", 1992) 275 | 276 | 277 |

    Example 2: object property that is itself another object. Suppose you define an object called person as follows: 278 |

    279 | function person(name, age, sex) { 280 | this.name = name 281 | this.age = age 282 | this.sex = sex 283 | } 284 | 285 |

    286 | And then instantiate two new person objects as follows: 287 |

    288 | rand = new person("Rand McNally", 33, "M") 289 | ken = new person("Ken Jones", 39, "M") 290 | 291 |

    292 | Then you can rewrite the definition of car to include an owner property that takes a person object, as follows: 293 |

    294 | function car(make, model, year, owner) { 295 | this.make = make; 296 | this.model = model; 297 | this.year = year; 298 | this.owner = owner; 299 | } 300 | 301 | 302 |

    To instantiate the new objects, you then use the following: 303 |

    304 | car1 = new car("Eagle", "Talon TSi", 1993, rand); 305 | car2 = new car("Nissan", "300ZX", 1992, ken) 306 | 307 | 308 |

    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 parameters for the owners. To find out the name of the owner of car2, you can access the following property: 309 |

    310 | car2.owner.name 311 | 312 | 313 | 314 | 315 |
    316 |

    return

    317 |

    A statement that specifies the value to be returned by a function. 318 | 319 | 320 |

    Syntax

    321 |
    322 | return expression
    323 | 
    324 | 325 | 326 |

    Examples

    327 |

    The following function returns the square of its argument, x, where x is a number. 328 |

    329 | function square( x ) { 330 | return x * x 331 | } 332 | 333 | 334 | 335 | 336 |
    337 |

    this

    338 |

    A keyword that you can use to refer to the current object. In general, in a method this refers to the calling object. 339 | 340 | 341 |

    Syntax

    342 |
    343 | this[.propertyName]
    344 | 
    345 | 346 | 347 |

    Examples

    348 |

    Suppose a function called validate validates an object's value property, given the object and the high and low values: 349 |

    350 | function validate(obj, lowval, hival) { 351 | if ((obj.value < lowval) || (obj.value > hival)) 352 | alert("Invalid Value!") 353 | } 354 | 355 |

    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: 356 |

    357 | <B>Enter a number between 18 and 99:</B> 358 | <INPUT TYPE = "text" NAME = "age" SIZE = 3 359 | onChange="validate(this, 18, 99)"> 360 | 361 | 362 | 363 | 364 |
    365 |

    var

    366 |

    A statement that declares a variable, optionally initializing it to a value. The scope of a variable is the current function or, for variables declared outside a function, the current application. 367 | 368 |

    Using var outside a function is optional; you can declare a variable by simply assigning it a value. However, it is good style to use var, and it is necessary in functions if a global variable of the same name exists. 369 | 370 | 371 |

    Syntax

    372 |
    373 | var varname [= value] [..., varname [= value] ]
    374 | 
    375 | 376 | varname is the variable name. It can be any legal identifier. 377 |
    value is the intial value of the variable and can be any legal expression. 378 | 379 |

    Examples

    380 | 381 | var num_hits = 0, cust_no = 0 382 | 383 | 384 | 385 | 386 |
    387 |

    while

    388 |

    A statement that creates a loop that evaluates an expression, and if it is true, executes a block of statements. The loop then repeats, as long as the specified condition is true. 389 | 390 | 391 |

    Syntax

    392 |
    393 | while (condition) {
    394 |    statements
    395 | }
    396 | 
    397 | 398 | condition is evaluated before each pass through the loop. If this condition evaluates to true, the statements in the succeeding block are performed. When condition evaluates to false, execution continues with the statement following statements. 399 |

    statements is a block of statements that are executed as long as the condition evaluates to true. Although not required, it is good practice to indent these statements from the beginning of the while statement. 400 | 401 |

    Examples

    402 |

    The following while loop iterates as long as n is less than three. 403 | 404 |

    405 | n = 0 406 | x = 0 407 | while( n < 3 ) { 408 | n ++ 409 | x += n 410 | } 411 | 412 | 413 |

    Each iteration, the loop increments n and adds it to x. Therefore, x and n take on the following values: 414 |

      415 |
    • After the first pass: n = 1 and x = 1 416 |
    • After the second pass: n = 2 and x = 3 417 |
    • After the third pass: n = 3 and x = 6 418 |
    419 | 420 |

    After completing the third pass, the condition n < 3 is no longer true, so the loop terminates. 421 | 422 | 423 | 424 |


    425 |

    with

    426 |

    A statement that establishes a 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. 427 | 428 | 429 |

    Syntax

    430 |
    431 | with (object){
    432 |     statements
    433 | }
    434 | 
    435 | 436 | object specifies the default object to use for the statements. The parentheses are required around object. 437 |
    statements is any block of statements. 438 | 439 |

    Examples

    440 |

    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. 441 |

    442 | var a, x, y 443 | var r=10 444 | with (Math) { 445 | a = PI * r * r 446 | x = r * cos(PI) 447 | y = r * sin(PI/2) 448 | } 449 | 450 | 451 | 452 | 453 |
    454 | 457 | 458 | -------------------------------------------------------------------------------- /js-1.0/stmtsov.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

    Overview of JavaScript Statements

    5 |

    JavaScript supports a compact set of statements that you can use to incorporate a great deal of interactivity in web pages. The statements are: 6 |

    31 | 32 |

    The following sections provide a brief overview of each statement. See the statements reference for detailed information about statement syntax. 33 | 34 | 35 |


    36 |

    Conditional Statements

    37 |

    Conditional statements let you perform certain actions based on a logical condition. You specify a condition to test and the commands to execute if the condition is true. JavaScript has one conditional statement: the if statement. 38 | 39 |

    if statement

    40 |

    An if statement is an either/or switch. If a specified condition is true, JavaScript performs certain statements. If the condition is false, JavaScript might perform other statements. An if statement looks as follows: 41 | 42 |

     43 | if (condition) {
     44 |    statements1 }
     45 | [else {
     46 |    statements2}]
     47 | 
    48 | 49 |

    The condition can be any JavaScript expression that evaluates to true or false. The conditional statements can be any JavaScript statements, including further nested if statements. Multiple statements must be enclosed in braces. 50 | 51 |

    Example. In the following example, the function checkData() returns true if the number of characters in a text object is three; otherwise, it displays an alert and returns false. 52 |

    53 | function checkData (){ 54 | if (document.form1.threeChar.value.length == 3) { 55 | return true} 56 | else { 57 | alert("Enter exactly three characters. " + document.form1.threeChar.value + " is not valid.") 58 | return false} 59 | } 60 | 61 | 62 | 63 |
    64 |

    Loop Statements

    65 |

    A loop is a set of commands that executes repeatedly until a specified condition is met. JavaScript supports two loop structures: for and while. In addition, the break and continue statements are used specifically with loops. 66 | 67 |

    Another statement, for...in, executes statements repeatedly but is used for object manipulation. See Object Manipulation Statements. 68 | 69 |

    for statement

    70 |

    A for loop repeats a loop until a specified condition evaluates to false. The JavaScript for loop is similar to the Java for loop and the traditional for loop in C. A for statement looks as follows: 71 | 72 |

     73 | for ([initial-expression;] [condition;] [increment-expression]) {
     74 |    statements
     75 | }
     76 | 
    77 | 78 |

    When a for loop is encountered, the initial-expression is executed. The statements are executed as long as condition evaluates to true. The increment-expression is performed on each pass through the loop. The sequence of execution is as follows: 79 |

      80 |
    1. The initializing expression initial-expression, if any, is executed. This expression usually initializes one or more loop counters, but the syntax allows an expression of any degree of complexity. 81 |
    2. The condition expression is evaluated. If the value of condition is true, the loop statements execute. If the value of condition is false, the for loop terminates. 82 |
    3. The update expression increment-expression executes. 83 |
    4. The statements execute and control returns to step 2. 84 |
    85 | 86 |

    Example. 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). The for statement declares the variable i and initializes it to zero. It checks that i is less than the number of options in the select object, performs the succeeding if statement, and increments i by one after each pass through the loop. 87 |

    88 | <SCRIPT> 89 | function howMany(selectObject) { 90 | var numberSelected=0 91 | for (i=0; i < selectObject.options.length; i++) { 92 | if (selectObject.options[i].selected==true) 93 | numberSelected++ 94 | } 95 | return numberSelected 96 | } 97 | </SCRIPT> 98 | <FORM NAME="selectForm"> 99 | <P><B>Choose some music types, then click the button below:</B> 100 | <BR><SELECT NAME="musicTypes" MULTIPLE> 101 | <OPTION SELECTED> R&B 102 | <OPTION> Jazz 103 | <OPTION> Blues 104 | <OPTION> New Age 105 | <OPTION> Classical 106 | <OPTION> Opera 107 | </SELECT> 108 | <P><INPUT TYPE="button" VALUE="How many are selected?" 109 | onClick="alert ('Number of options selected: ' + howMany(document.selectForm.musicTypes))"> 110 | </FORM> 111 | 112 | 113 |

    while statement

    114 |

    A while statement repeats a loop as long as a specified condition evaluates to true. A while statement looks as follows: 115 | 116 |

    117 | while (condition) {
    118 |    statements
    119 | }
    120 | 
    121 | 122 |

    If the condition becomes false, the statements within the loop stop executing and control passes to the statement following the loop. 123 | 124 |

    The condition test occurs only when the statements in the loop have been executed and the loop is about to be repeated. That is, 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, each time control passes through the loop. 125 | 126 |

    Example 1. The following while loop iterates as long as n is less than three. 127 | 128 |

    129 | n = 0 130 | x = 0 131 | while( n < 3 ) { 132 | n ++ 133 | x += n 134 | } 135 | 136 | 137 |

    Each iteration, the loop increments n and adds it to x. Therefore, x and n take on the following values: 138 |

      139 |
    • After the first pass: n = 1 and x = 1 140 |
    • After the second pass: n = 2 and x = 3 141 |
    • After the third pass: n = 3 and x = 6 142 |
    143 | 144 |

    After completing the third pass, the condition n < 3 is no longer true, so the loop terminates. 145 | 146 |

    Example 2: infinite loop. Make sure the condition in a loop eventually becomes false; otherwise, the loop will never terminate. The statements in the following while loop execute forever because the condition never becomes false: 147 | 148 |

    149 | while (true) { 150 | alert("Hello, world") } 151 | 152 | 153 |

    break statement

    154 |

    The break statement terminates the current while or for loop and transfers program control to the statement following the terminated loop. A break statement looks as follows: 155 | 156 |

    157 | break
    158 | 
    159 | 160 |

    Example. The following function has a break statement that terminates the while loop when i is 3, and then returns the value 3 * x. 161 |

    162 | function testBreak(x) { 163 | var i = 0 164 | while (i < 6) { 165 | if (i == 3) 166 | break 167 | i++ 168 | } 169 | return i*x 170 | } 171 | 172 | 173 |

    continue statement

    174 |

    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. A continue statement looks as follows: 175 |

    176 | continue
    177 | 178 | 179 |

    In contrast to the break statement, continue does not terminate the execution of the loop entirely. Instead, 180 |

      181 |
    • In a while loop, it jumps back to the condition. 182 |
    • In a for loop, it jumps to the increment-expression. 183 |
    184 | 185 |

    Example. 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. 186 |

    187 | i = 0 188 | n = 0 189 | while (i < 5) { 190 | i++ 191 | if (i == 3) 192 | continue 193 | n += i 194 | } 195 | 196 | 197 | 198 |
    199 |

    Object Manipulation Statements

    200 |

    JavaScript has several ways of manipulating objects: for...in statement, new operator, this keyword, and with statement. 201 | 202 |

    for...in statement

    203 |

    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: 204 | 205 |

    206 | for (variable in object) {
    207 |    statements }
    208 | 
    209 | 210 |

    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. 211 |

    212 | function dump_props(obj, obj_name) { 213 | var result = "" 214 | for (var i in obj) { 215 | result += obj_name + "." + i + " = " + obj[i] + "<BR>" 216 | } 217 | result += "<HR>" 218 | return result 219 | } 220 | 221 | 222 |

    For an object car with properties make and model, result would be: 223 |

    224 | car.make=Ford 225 | car.model=Mustang 226 | 227 | 228 |

    new operator

    229 |

    The new operator lets you create an instance of a user-defined object type. Use new as follows: 230 | 231 |

    232 | objectName = new objectType ( param1 [,param2] ...[,paramN] )
    233 | 
    234 | 235 |

    For information, see new in the statements reference. 236 | 237 |

    this keyword

    238 |

    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: 239 | 240 |

    241 | this[.propertyName]
    242 | 
    243 | 244 |

    Example. Suppose a function called validate validates an object's value property, given the object and the high and low values: 245 |

    246 | function validate(obj, lowval, hival) { 247 | if ((obj.value < lowval) || (obj.value > hival)) 248 | alert("Invalid Value!") 249 | } 250 | 251 |

    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: 252 |

    253 | <B>Enter a number between 18 and 99:</B> 254 | <INPUT TYPE = "text" NAME = "age" SIZE = 3 255 | onChange="validate(this, 18, 99)"> 256 | 257 | 258 |

    with statement

    259 |

    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: 260 | 261 |

    262 | with (object){
    263 |     statements
    264 | }
    265 | 
    266 | 267 |

    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. 268 |

    269 | var a, x, y 270 | var r=10 271 | with (Math) { 272 | a = PI * r * r 273 | x = r * cos(PI) 274 | y = r * sin(PI/2) 275 | } 276 | 277 | 278 | 279 |
    280 |

    Comments

    281 |

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

      283 |
    • Comments on a single line are preceded by a double-slash (//). 284 |
    • Comments that span multiple lines are preceded by a /* and followed by a */. 285 |
    286 | 287 |

    Example.. The following example shows two comments. 288 |

    289 | // This is a single-line comment. 290 | /* This is a multiple-line comment. It can be of any length, and 291 | you can put whatever you want here. */ 292 | 293 | 294 | 295 |
    296 | 297 | 300 |

    301 | 302 | -------------------------------------------------------------------------------- /js-1.0/toc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

    JavaScript Basics

    5 | Introduction
    6 | Navigator Scripting
    7 | Navigator Objects
    8 | Using Windows and Frames 9 | 10 |

    Language Concepts

    11 | Values, Names, Literals
    12 | Expressions, Operators
    13 | Object Model
    14 | Built-in Objects, Functions
    15 | Statements Overview 16 | 17 |

    Reference

    18 | Objects
    19 | Methods, Functions
    20 | Properties
    21 | Event Handlers
    22 | Statements
    23 | Reserved Words
    24 | Color Values
    25 | 26 | 27 | 28 |
    29 | Copyright © 1995-1996 Netscape Communications 30 | Corporation
    31 | -------------------------------------------------------------------------------- /js-1.0/winframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

    Using windows and frames

    4 |

    JavaScript lets you create and open windows for presenting HTML text, form objects, and frames. The window object is the top-level object in the JavaScript client hierarchy. Form elements and all JavaScript code exists in documents that are loaded into windows. By understanding how windows work, you can control and manipulate these windows. 5 | 6 |

    12 | 13 | 14 | 15 |
    16 |

    Opening and closing windows

    17 |

    A window is created automatically when a user launches Navigator, and a user can open a window by choosing New Web Browser from the Navigator's File menu. A user can close a window by choosing either Close or Exit from the Navigator's File menu. You can also open and close windows programmatically. 18 | 19 |

    Opening a window

    20 |

    You can create a window with the open method. The following statement creates a window called msgWindow that displays the contents of the file sesame.html: 21 |

    22 | msgWindow=window.open("sesame.html") 23 | 24 | 25 |

    The following statement creates a window called homeWindow that displays the Netscape home page: 26 |

    27 | homeWindow=window.open("http://www.netscape.com") 28 | 29 | 30 |

    Windows can have two names. The following statement creates a window with two names. The first name, "msgWindow", is used when referring to the window's properties, methods, and containership; the second name, "displayWindow", is used when referring to the window as the target of a form submit or hypertext link. 31 | 32 |

    33 | msgWindow=window.open("sesame.html","displayWindow") 34 | 35 | 36 |

    When you create a window, a window name is not required. But if you want to refer to a window from another window, the window must have a name. For more information on using window names, see Referring to windows and frames. 37 | 38 |

    When you open a window, you can specify attributes such as the window's height and width and whether the window contains a toolbar, location field, or scrollbars. The following statement creates a window without a toolbar but with scrollbars: 39 |

    40 | msgWindow=window.open 41 | ("sesame.html","displayWindow","toolbar=no,scrollbars=yes") 42 | 43 | 44 |

    For details on these window attributes, see the open method. 45 | 46 |

    Closing a window

    47 |

    You can close a window programmatically with the close method. You cannot close a frame without closing the entire parent window. 48 | 49 |

    All of the following statements close the current window: 50 |

    51 | window.close() 52 | self.close() 53 | // Do not use the following statement in an event handler 54 | close() 55 | 56 | 57 |

    The following statement closes a window called msgWindow: 58 |

    59 | msgWindow.close() 60 | 61 | 62 | 63 | 64 |
    65 |

    Using frames

    66 |

    A frame is a special type of window that can display multiple, independently scrollable frames on a single screen, each with its own distinct URL. Frames can point to different URLs and be targeted by other URLs, all within the same window. A series of frames makes up a page. 67 | 68 |

    The following diagram shows a window containing three frames: 69 |

    70 | This frame is This frame is 71 | named listFrame named contentFrame 72 | | | 73 | | | 74 | -------------v------------------------------v---------- 75 | | Music Club | Toshiko Akiyoshi | 76 | | Artists | Interlude | 77 | | | | 78 | | Jazz | The Beatles | 79 | | - T. Akiyoshi | Please Please Me | 80 | | - J. Coltrane | | 81 | | - M. Davis | Betty Carter | 82 | | - D. Gordon | Ray Charles and Betty Carter | 83 | | | | 84 | | Soul | Jimmy Cliff | 85 | | - B. Carter | The Harder They Come | 86 | | - R. Charles | | 87 | | ... | ... | 88 | ------------------------------------------------------- 89 | | Alphabetical By category Musician Descriptions | 90 | ----------------^-------------------------------------- 91 | | 92 | | 93 | This frame is named 94 | navigateFrame 95 | 96 | 97 | 98 |

    Creating a frame

    99 |

    You create a frame by using the <FRAMESET> tag in an HTML document. The <FRAMESET> tag is used in an HTML document whose sole purpose is to define the layout of frames that make up a page. 100 | 101 |

    Example 1. The following statement creates the frameset shown in the previous diagram. 102 |

    103 | <FRAMESET ROWS="90%,10%"> 104 | <FRAMESET COLS="30%,70%"> 105 | <FRAME SRC=category.html NAME="listFrame"> 106 | <FRAME SRC=titles.html NAME="contentFrame"> 107 | </FRAMESET> 108 | <FRAME SRC=navigate.html NAME="navigateFrame"> 109 | </FRAMESET> 110 | 111 | 112 |

    The following diagram shows the hierarchy of the frames. All three frames have the same parent, even though two of the frames are defined within a separate frameset. This is because a frame's parent is its parent window, and a frame, not a frameset, defines a window. 113 |

    114 | top 115 | | 116 | +--listFrame (category.html) 117 | | 118 | +--contentFrame (titles.html) 119 | | 120 | +--navigateFrame (navigate.html) 121 | 122 | 123 |

    You can refer to the previous frames using the frames array as follows. (For information on the frames array, see the frame object.) 124 |

      125 |
    • listFrame is top.frames[0] 126 |
    • contentFrame is top.frames[1] 127 |
    • navigateFrame is top.frames[2] 128 |
    129 | 130 |

    Example 2. Alternatively, you could create a window like the previous one but in which the top two frames have a separate parent from navigateFrame. The top-level frameset would be defined as follows: 131 | 132 |

    133 | <FRAMESET ROWS="90%,10%"> 134 | <FRAME SRC=muskel3.html NAME="upperFrame"> 135 | <FRAME SRC=navigate.html NAME="navigateFrame"> 136 | </FRAMESET> 137 | 138 | 139 |

    The file muskel3.html contains the skeleton for the upper frames and defines the following frameset: 140 |

    141 | <FRAMESET COLS="30%,70%"> 142 | <FRAME SRC=category.html NAME="listFrame"> 143 | <FRAME SRC=titles.html NAME="contentFrame"> 144 | </FRAMESET> 145 | 146 | 147 |

    The following diagram shows the hierarchy of the frames. upperFrame and navigateFrame share a parent: the top window. listFrame and contentFrame share a parent: upperFrame. 148 |

    149 | top 150 | | 151 | | +--listFrame 152 | | | (category.html) 153 | +---upperFrame------| 154 | | (muskel3.html) | 155 | | +--contentFrame 156 | | (titles.html) 157 | | 158 | +---navigateFrame 159 | (navigate.html) 160 | 161 | 162 |

    You can refer to the previous frames using the frames array as follows. (For information on the frames array, see the frame object.) 163 |

      164 |
    • upperFrame is top.frames[0] 165 |
    • navigateFrame is top.frames[1] 166 |
    • listFrame is upperFrame.frames[0] or top.frames[0].frames[0] 167 |
    • contentFrame is upperFrame.frames[1] or top.frames[0].frames[1] 168 |
    169 | 170 | 171 |

    Updating frames

    172 |

    You can update the contents of a frame by using the location property to set the URL, as long as you specify the frame hierarchy. 173 | 174 |

    For example, suppose you are using the frameset described in Example 2 in the previous section. If you want users to be able to close the frame containing the alphabetic or categorical list of artists (in the frame listframe) and view only the music titles sorted by musician (currently in the frame contentFrame), you could add the following button to navigateFrame. 175 | 176 |

    If you want users to be able to close the frame containing the alphabetic or categorical list of artists (in the frame listframe) and view only the music titles sorted by musician (currently in the frame contentFrame), you could add the following button to navigateFrame. 177 |

    178 | <INPUT TYPE="button" VALUE="Titles Only" 179 | onClick="top.frames[0].location='artists.html'"> 180 | 181 | 182 |

    When a user clicks this button, the file artists.html is loaded into the frame upperFrame; the frames listFrame and contentFrame close and no longer exist. 183 | 184 |

    Referring to and navigating among frames

    185 |

    Because a frame is a type of window, you refer to frames and navigate among frames the same as you do with a window. See Referring to windows and frames and Navigating among windows. 186 | 187 | 188 |

    Frame example

    189 |

    If the frameset in the previous section is designed to present the available titles for a music club, the frames and their HTML files could have the following content: 190 |

      191 |
    • category.html, in the frame listFrame, contains a list of musicians sorted by category. 192 |
    • titles.html, in the frame contentFrame, contains an alphabetical list of each musician and the titles available for that musician. 193 |
    • navigate.html, in the frame navigateFrame, contains hypertext links that let the user choose how the musicians are displayed in listFrame: in an alphabetical list or a categorical list. This file also defines a hypertext link that lets the user display a description of each musician. 194 |
    • An additional file, alphabet.html, contains a list of musicians sorted alphabetically. This file is displayed in listFrame when the user clicks the link for an alphabetical list. 195 |
    196 | 197 |

    The file category.html (the categorical list) contains code similar to the following: 198 |

    199 | <B>Music Club Artists</B> 200 | <P><B>Jazz</B> 201 | <LI><A HREF=titles.html#0001 TARGET="contentFrame">Toshiko Akiyoshi</A> 202 | <LI><A HREF=titles.html#0006 TARGET="contentFrame">John Coltrane</A> 203 | <LI><A HREF=titles.html#0007 TARGET="contentFrame">Miles Davis</A> 204 | <LI><A HREF=titles.html#0010 TARGET="contentFrame">Dexter Gordon</A> 205 | 206 | <P><B>Soul</B> 207 | <LI><A HREF=titles.html#0003 TARGET="contentFrame">Betty Carter</A> 208 | <LI><A HREF=titles.html#0004 TARGET="contentFrame">Ray Charles</A> 209 | ... 210 | 211 | 212 |

    The file alphabet.html (the alphabetical list) contains code similar to the following: 213 |

    214 | <B>Music Club Artists</B> 215 | <LI><A HREF=titles.html#0001 TARGET="contentFrame">Toshiko Akiyoshi</A> 216 | <LI><A HREF=titles.html#0002 TARGET="contentFrame">The Beatles</A> 217 | <LI><A HREF=titles.html#0003 TARGET="contentFrame">Betty Carter</A> 218 | <LI><A HREF=titles.html#0004 TARGET="contentFrame">Ray Charles</A> 219 | ... 220 | 221 | 222 |

    The file navigate.html (the navigational links at the bottom of the screen) contains code similar to the following. Notice that the target for artists.html is "_parent". When the user clicks this link, the entire window is overwritten, because the top window is the parent of navigateFrame. 223 |

    224 | <A HREF=alphabet.html TARGET="listFrame"><B>Alphabetical</B></A> 225 | &nbsp&nbsp&nbsp 226 | <A HREF=category.html TARGET="listFrame"><B>By category</B></A> 227 | &nbsp&nbsp&nbsp 228 | <A HREF="artists.html" TARGET="_parent"> 229 | <B>Musician Descriptions</B></A> 230 | 231 | 232 |

    The file titles.html (the main file, displayed in the frame on the right) contains code similar to the following: 233 |

    234 | <!-----------------------------------------------------------------> 235 | <A NAME="0001"><H3>Toshiko Akiyoshi</H3></A> 236 | <P>Interlude 237 | <!-----------------------------------------------------------------> 238 | <A NAME="0002"><H3>The Beatles</H3></A> 239 | <P>Please Please Me 240 | <!-----------------------------------------------------------------> 241 | <A NAME="0003"><H3>Betty Carter</H3></A> 242 | <P>Ray Charles and Betty Carter 243 | ... 244 | 245 | 246 |

    For details on the syntax for creating a frame, see the frame object. 247 | 248 | 249 | 250 |


    251 |

    Referring to windows and frames

    252 |

    The name you use to refer to a window depends on whether you are referring to a window's properties, methods, and event handlers or are referring to the window as the target of a form submit or hypertext link. 253 | 254 |

    Since the window object is the top-level object in the JavaScript client hierarchy, the window is essential for specifying the containership of objects in any window. 255 | 256 | 257 |

    Referring to a window's properties, methods, and event handlers

    258 |

    You can refer to the properties, methods, and event handlers of the current window or another window (if the other window is named) in any of the following ways: 259 | 260 |

      261 |
    • self or window. self and window are synonyms for the current window, and you can optionally use them to refer to the current window. For example, you can close the current window by calling either window.close() or self.close(). 262 | 263 |
    • top or parent. top and parent are also synonyms that can be used in place of the window name. top refers to the top-most Navigator window, and parent refers to a window containing a frameset. For example, the statement parent.frame2.document.bgColor="teal" changes the background color of the frame named frame2 to teal; frame2 is a frame in the current frameset. 264 | 265 |
    • The name of a window variable. The window variable is the variable that is specified when a window is opened. For example, msgWindow.close() closes a window called msgWindow. However, when you open or close a window within an event handler, you must specify window.open() or window.close() instead of simply using open() or close(). Due to the scoping of static objects in JavaScript, a call to close() without specifying an object name is equivalent to document.close(). 266 | 267 |
    • Omit the window name. Because the existence of the current window is assumed, you do not have to reference the name of the window when you call its methods and assign its properties. For example, close() closes the current window. 268 |
    269 | 270 |

    For more information on these methods of referring to windows, see the window object. 271 | 272 |

    Example 1: refer to the current window. The following statement refers to a form named musicForm in the current window. The statement displays an alert if a checkbox is checked. 273 |

    274 | if (self.document.musicForm.checkbox1.checked) { 275 | alert('The checkbox on the musicForm is checked!')} 276 | 277 | 278 |

    Example 2: refer to another window. The following statements refer to a form named musicForm in a window named checkboxWin. The statements determine if a checkbox is checked, check the checkbox, determine if the second option of a select object is selected, and select the second option of the select object. Even though object values are changed in checkboxWin, the current window remains active: checking the checkbox and selecting the selection option do not give focus to the window. 279 |

    280 | // Determine if a checkbox is checked 281 | if (checkboxWin.document.musicForm.checkbox2.checked) { 282 | alert('The checkbox on the musicForm in checkboxWin is checked!')} 283 | 284 | // Check the checkbox 285 | checkboxWin.document.musicForm.checkbox2.checked=true 286 | 287 | // Determine if an option in a select object is selected 288 | if (checkboxWin.document.musicForm.musicTypes.options[1].selected) 289 | {alert('Option 1 is selected!')} 290 | 291 | // Select an option in a select object 292 | checkboxWin.document.musicForm.musicTypes.selectedIndex=1 293 | 294 | 295 |

    Example 3: refer to a frame in another window. The following statement refers to a frame named frame2 that is in a window named window2. The statement changes the background color of frame2 to violet. The frame name, frame2, must be specified in the <FRAMESET> tag that creates the frameset. 296 |

    297 | window2.frame2.document.bgColor="violet" 298 | 299 | 300 | 301 |

    Referring to a window in a form submit or hypertext link

    302 |

    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). The window you specify is the window that the link is loaded into or, for a form, the window that server responses are displayed in. 303 | 304 |

    Example 1: second window. The following example creates a hypertext link to a second window. The example has a button that opens a window named window2, then a link that loads the file doc2.html into the newly opened window, then a button that closes the window. 305 |

    306 | <P> 307 | <INPUT TYPE="button" VALUE="Open window2" 308 | onClick="msgWindow=window.open('','window2','resizable=no,width=200,height=200')"> 309 | <P> 310 | <A HREF="doc2.html" TARGET="window2"> Load a file into window2</A> 311 | <P> 312 | <INPUT TYPE="button" VALUE="Close window2" 313 | onClick="msgWindow.close()"> 314 | 315 | 316 |

    Example 2: anchor in a second window. The following example creates a hypertext link to an anchor in a second window. The link displays the anchor named numbers in the file doc2.html in the window window2. If window2 does not exist, it is created. 317 |

    318 | <A HREF=doc2.html#numbers TARGET="window2">Numbers</A> 319 | 320 | 321 |

    Example 3: frame name. The following example creates a hypertext link to an anchor in a frame. The link displays the anchor named abs_method in the file sesame.html in the frame named "contentFrame". The frame must be within the current frameset and the frame name must be defined in the NAME attribute of a <FRAME> tag. 322 |

    323 | <A HREF=sesame.html#abs_method TARGET="contentFrame">abs</A> 324 | 325 | 326 |

    Example 4: literal frame name. The following example creates a hypertext link to a file. The link displays the file named artists.html in the parent window of the current frameset. This link object appears in a frame within a frameset, and when the user clicks the link, all frames in the frameset disappear and the content of artists.html is loaded into the parent window. 327 |

    328 | <A HREF="artists.html" TARGET="_parent"> 329 | <B>Musician Descriptions</B></A> 330 | 331 | 332 | 333 | 334 |
    335 |

    Navigating among windows

    336 |

    Many Navigator windows can be open at the same time. The user can move among these windows by clicking them to give them focus. 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. Although you can change an object's values in a second window, that does not make the second window active: the current window remains active. 337 | 338 |

    The active window is the window that has focus. When a window has focus, it is brought to the front and changes in some visual way. For example, the window's title bar might change to a different color. The visual cue varies depending on the platform you are using. 339 | 340 |

    Example 1: give focus to an object in another window. The following statement gives focus to a text object named city in a window named checkboxWin. Because the text object is gaining focus, checkboxWin also gains focus and becomes the active window. The example also shows the statement that creates checkboxWin. 341 |

    342 | checkboxWin=window.open("doc2.html") 343 | ... 344 | checkboxWin.document.musicForm.city.focus() 345 | 346 | 347 |

    Example 2: give focus to another window using a hypertext link. The following statement specifies window2 as the target of a hypertext link. When the user clicks the link, focus switches to window2. If window2 does not exist, it is created. 348 |

    349 | <A HREF="doc2.html" TARGET="window2"> Load a file into window2</A> 350 | -------------------------------------------------------------------------------- /js-2.0/javascript2.0_ evolving_a_language_for_evolving_systems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwaldron/js-history/b62e5b6c8c80c2d95b47518456f3fb00470122d2/js-2.0/javascript2.0_ evolving_a_language_for_evolving_systems.pdf -------------------------------------------------------------------------------- /misc/ES4-language-overview.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rwaldron/js-history/b62e5b6c8c80c2d95b47518456f3fb00470122d2/misc/ES4-language-overview.pdf --------------------------------------------------------------------------------