How It Works 20
The first line in the script block at the top of the page defines a variable with page-level scope. This is an array that contains your list of image sources. var mylmages new Next you have the changelmg function, which will be connected to the onclick event handler of an lt IMG gt tag surrounding each of your images. You are using the same function for both images' onclick event handlers and indeed can connect one function to as many event handlers as you like. You pass this function one...
A MultiDimensional Array
Suppose you want to store a company's personnel information in an array. You might have data such as names, ages, addresses, and so on. One way to create such an array would be to store the information sequentially the first name in the first element of the array, then the corresponding age in the next element, the address in the third, the next name in the fourth element, and so on. Your array could look something like this This would work, but there is a neater solution using a...
The top Property
Using the parent property can get a little tedious when you want to access the very top window from a frame quite low down in the hierarchy of frames and window objects. An alternative is the window object's top property. This returns a reference to the window object of the very top window in a frame hierarchy. In the current example, this is top window. For instance, in the example you just saw, this code Although, because the window is a global object, you could shorten that to just this So...
Multiple Conditions Inside an if Statement
The previous section started by asking how you could use the condition Is degFahren greater than zero, but less than 100 One way of doing this would be to use two if statements, one nested inside another. Nested simply means that there is an outer if statement, and inside this an inner if statement. If the condition for the outer if statement is true, then and only then the nested inner if statement's condition will be tested. Using nested if statements, your code would be document.write...
How It Works 33
You ve already seen how the code defining the top window in complex_frameset_page.htm works, as it is very similar to the previous example. However, you ll just look quickly at the lt frameset gt tags where, as you can see, the names of the windows are defined in the names of the lt frame gt tags. lt frameset cols 200, gt Notice also that the cols attribute of the lt frameset gt tag is set to 200, . This means that the first frame will occupy a column 200 pixels wide, and the other frame will...
How It Works 59
You ve hopefully made this example very transparent by adding several alerts to demonstrate where you are along each section of the tree. You ve also named the variables with their various elements, to give a clearer idea of what is stored in each variable. You could just as easily have named them a, b, c, d, and e, so don t think you need to be bound by this naming convention. You start at the top of the script block by retrieving the whole document using the documentElement property. var...
Displaying Errors in Firefox
Firefox keeps quiet about your errors, so if things go wrong you won t see any pop-up boxes warning you or alarm bells going off. However, one of its developer tools is the JavaScript Console, which contains details of any JavaScript problems on your page. It also reports other problems, such as invalid CSS. To view this console from Firefox, go to the Tools menu and select JavaScript Console, as shown in Figure 2-3. File Edit View Go Bookmarks Tools Help Getting Started 3- Latest Headline...