So, you want to set things to happen after a certain amount of time? Well, the setTimeout function can help you create some nice scripts that will use time delays to make things happen. Let's take a look at how to call the setTimeout function: setTimeout("yourfunction()",1000); The first parameter is a string, which is going to be the function you want to use. This function was named "myfunction()". The second parameter is a number. This number is going to be the number of milliseconds the browser should wait before executing your function. Above, we have 1000 milliseconds, which will be 1 second. Now, what can you do with it? Let me start with an example that shows you the setTimeout function in action. Click the button to the right of the text box below and watch what happens! Now, how did I get that text to change a second time while you were able to just watch? Let's look at the script for this trick: --------------------------------------------------------------------------------
  
-------------------------------------------------------------------------------- We use the HEAD section to define our two functions. The first function is named "newtext()". We call this function when the user clicks the button we created. As you can see, we changed the value of the text in the text box by using the name of the form and the name of the textbox: document.myform.mytext.value="Hey! I have changed!"; The next command is what makes the second change happen. We call the function "moretext()" after 1000 milliseconds: setTimeout("moretext()",1000); Now, the function "moretext()" changes the value in the form box one more time, after waiting 1 second: document.myform.mytext.value="I just change with the time!"; Now, in the BODY section, we simply put the code for the form and the textbox. Remember to give your form and your textbox names. That is how we are able to change the text in the box using the functions. The name for the form above was "myform", and the name of the text box was "mytext". If you need more help on how to access form elements, see the tutorial Beginning with Forms. Arrays are one way of keeping a program more organized. They allow you to do some things that are difficult without them. Arrays are usually a group of the same variable type that use an index number to distinguish them from each other. Suppose you wanted to write out 5 quotes, and use variables for each one of the quotes. You could define 5 variables: quote1="I like JavaScript."; quote2="I used to like Java."; quote3="JavaScript rules."; quote4="Help! JavaScript Error!"; quote5="Just Kidding."; However, a better way may be to use an array. To define an array, we need to follow the following form: var Name_of_Array= new Array(number_of_elements); Name_of_Array would be the name you want to give the array variable, the number_of_elements is the number of variables you want the array to store. So, for our quotes, we could write: var quote= new Array(5); Now, to assign values, we are going to use what is called an index number, and place it inside brackets. We attach this right on the end of the word quote, so our first quote would be: quote[0] I know, zero instead of 1. Arrays just work that way, the first element is always zero and the last element is always one less than what you define as the number of elements. In this case, our first element is quote[0], the last is quote[4]. So to assign the values we had, we could use a straight assignment, like this: var quote= new Array(5) quote[0]="I like JavaScript."; quote[1]="I used to like Java."; quote[2]="JavaScript rules."; quote[3]="Help! JavaScript Error!"; quote[4]="Just Kidding."; Notice that when we do this, we leave off the semiclon at the end of the array definition, and use semicolons at the end of each element we define. So far, it has only made things more complicated. However, this array can now be used as part of a loop, using the value of the index numbers as a variable: var x=0; for (x=0; x<5; x++) { alert(quote[x]); } This uses the variable x in place of each index number, and runs the alert for all 5 elements in our array. The first time through, you would get an alert with quote[0], the second time, quote[1], and so on. If you need more on for loops, see the conditional tutorial. I may not have explained the ++ operator before. x++ means that we add one to the value of x. In a similar fashion, we can subtract one from x with x--. This is how we are able to go from x being 0 to x being equal to 4. It stops at 4 because part of the condition is that the loop is only run while x is less than 5. So the last time it runs, x is equal to 5 and it does not go any further. The script in action is a bit annoying. You can write this script in the head section. We will make this into a function, and call it from a link (the link must be in the body):
Click Here, I dare you! Here, try it out. Just don't get angry! Click Here, I dare you! You could also assign the values of the array using a loop. This would allow the viewer to assign the values using prompts, and then you could alert them with their own words! var quote= new Array(5); var y=0; for (y=0; y<5; y++) { quote[y]=prompt('Enter a Quote!',' '); } Notice that we just defined the array, without assigning initial values. Don't forget the semicolon! Then we get the values by letting the viewer enter them through a prompt. quote[y] uses the value of y each time it is run. So, you are assigning quote[0] the first time, quote[1] the second time, and so on. The complete script is below, and it is even more annoying than the other one!
Click Here, I dare you! Here, try it out. Drive yourself insane... Click Here, I dare you! The examples here could annoy people, but they do show you how arrays can be useful. There are certainly more useful ways to use them! I know you can think of a few... Associative arrays give you another way to store information. Using associative arrays, you can call the array element you need using a string rather than a number, which is often easier to remember. The downside is that these aren't as useful in a loop because they do not use numbers as the index value. An associative array is defined just like a regular array, but we insert some text in the place we had numbers in the regular arrays: var my_cars= new Array() my_cars["cool"]="Mustang"; my_cars["family"]="Station Wagon"; my_cars["big"]="SUV"; Now we can get the Word Mustang later in the script by remembering it is the "cool" car, so we would use my_cars["cool"]. This could be used to prompt a user to input the type of car he/she would prefer. Then you can send back what you think the viewer should buy based on the input:
You can try it out with the button below. Of course, most of the time you will end up with the "I don't know" answer-- unless you happen to type in one of the three car types we used! Well, that should take car of associative arrays for now. Try them out and see what kind of ideas you can come up with to make some useful scripts! Prelaoding images is a technique often used in Rollover Effects or other image scripts which work more quickly when the images for them are loaded as soon as possible. What javascript does is allow you to start loading the images in the HEAD section of your page, which means that with this technique (unless the images are large or great in number) your viewers will have the necessary images in their browser's cache before the script starts to run. This way, an image rollover will be less likely to make the viewers wait for the browser to download the second image, because it is in their browser's cache. To get this going, you need to have a small section of script in the HEAD section of your page. Here is a sample of a script that preloads a single image: The first command defines a new image object, giving it a width of 100 and a height of 25. You would replace these with the width and height of your image. The second defines the url or web address of the image. You would replace this with the url of your image. Not too bad now, is it? However, there is a chance your viewer will come through with an older browser which doesn't support the image object. So, to be on the safe side you may wish to implement a form of Browser Detection or Object Detection to keep from giving the older browsers a javascript error. I will use the shorter one here, which is object detection. For more on object detection, see the tutorial on what it can do. Here, we want to know if the image object exists, which in javascript is "document.images". So, we just need to check for it with an if condition, and then run the preloading code: There, now you have the code to preload (what a rhyme!). If you want to do this for multiple images, just be sure to assign them a different name-- such as pic2, pic3, and so on. Adjust your width, height, and urls accordingly. You will have two lines for each image. For example, to preload three images, you would use a code like this: In the next section you will see an example of how prelaoding works with the image rollover script. The first section will use browser detection, while the following sections will use object detection like we did here. Using a javascript to change an image when someone moves their mouse over it has become quite popular. I've heard it called many things: "hover buttons", "rollover", and "image highlighter" are a few. What happens is that we use two images, a link, and a javascript to make a clickable image link that is "highlighted" when a mouse passes over it. To begin, you will need to make yourself two images of the same size, making whatever changes you would like to the second one. Below is an example where I chose to make an image with blue text and one in red text. The red-text image is what I want people to see when they move their mouse over the blue-text image. OK, that is the easy part. Now we have to have a script that will do all the work for us. I'm going to go ahead and put the whole thing below, and explain the script in parts afterward. I got this script from a free script page, did some formatting for readability, changed some variable names, and added a check for the image object. Here is the code for the HEAD section of your page: -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- Part 1: Browser Check All right, the first step is to check for a browser that supports all the functions and declarations we will be using. This is done with Object Detection: if (document.images) { statements (see code above/explanation below) } This checks to ensure the browser supports the image object before it preloads the images. This way, you can avoid javascript errors in older browsers. Part 2: Define and Load Your Images Now, we get the images involved in the scheme here: if (document.images) { This checks to ensure the browser supports the image object. pic1on= new Image(100,25); This defines a new image called "pic1on" with a width of 100 and a height of 25. pic1on.src="shoes2.gif"; This gives the source, or url of the image. This allows it to load now so users don't wait for a new image to load when they pass their mouse over it later. Be sure this is the url of your 2nd image. This is the one you want people to see when their mouse passes over. pic1off= new Image(100,25); Now you define your default, or 1st image. pic1off.src="shoes1.gif"; Give the url of your default image so it is loaded. } : Ends the image defining and loading statements. Function 1: The mouseover Function Now we get to the function that will be triggered by the mouse moving over the image: function lightup(imgName) { This defines a function named "lightup". It is reading in a parameter called "imgName". "imgName" is going to be the name="pic1" attribute of the 2nd image from our HTML document. It is sent to this function when we call it later in the HTML document (see below). imgName turns out to be "pic1". The "{" begins the group of statements for the function. if (document.images) { Another check and beginning of statements for browsers with the image object. imgOn=eval(imgName + "on.src"); This defines the variable "imgOn" as the sum of the variable "imgName" and the string "on.src". Remember, the function read in "imgName" as "pic1", so the sum ends up as "pic1on.src", which is defined earlier as the url of our 2nd image. document[imgName].src= imgOn; Now, we define imgOn for the document, so it loads the correct image. By substituting what we got for imgOn a moment ago, and substituting "pic1" for imgName (which was sent to the function), we get this: document[pic1].src=pic1on.src. This is why we need to use the name="pic1" attribute in the image tag in our HTML later. This makes a reference to an image in the document by the name of "pic1". The new source (url) for the image is now the value of "pic1on.src", which we defined earlier as "shoes2.gif", our 2nd image. A bit complicated at first, but it works out nicely, doesn't it? } } : These end the "n3" statements and the function statements. Function 2: When the Mouse Leaves the Image function turnoff(imgName) { if (document.images) { imgOff=eval(imgName + "off.src"); document[imgName].src= imgOff; } } //----> This function does the same thing as the last one, except that it occurs when the mouse moves off the image. Thus, I named the function "turnoff" since it turns the previous function "off" and returns to the 1st image. After the function ends, the script and HEAD tags are closed. Finally, the HTML! Now, go down into your BODY section and find out where you would like your image to go. You will then put in the following linked image code. You should place everything on one line, I have it this way only for readability. Notice how we call our function "lightup" with the parameter 'pic1' on the Mouseover. We then call the function "turnoff" with the parameter 'pic1' on the Mouseout. The action is all done in our link tag. You can link to any url you wish here, and that will be where the user goes if they click the image. In the image tag, use your first (default) image as the image source. Also, be sure you use the name="pic1" attribute, as well as defining your height and width. This will make sure the script knows the name, height, and width of your image and will run smoothly. The border attribute is up to you. I chose zero for mine because I wanted the image to look like text. The Final Product: A Changing, Linked Image Yes, there it is. Move your mouse over it and see the text turn red! You can click it if you want, but you'll end up back at the main JavaScript Page...... But I Want to do this for Multiple Images! No problem. You can use it for as many images as you wish. Just be sure to define your other images along with your first. Remember, you need two images for every one you want to change. To add extras, define them first back in the script in the HEAD section: if (document.images) { pic1on= new Image(100,25); pic1on.src="../images/shoes2.gif"; pic2on= new Image(100,25); pic2on.src="../images/story2.gif"; pic1off= new Image(100,25); pic1off.src="../images/shoes1.gif"; pic2off= new Image(100,25); pic2off.src="../images/story1.gif"; } Now, be sure you name it correctly in the HTML in the BODY section. For the new image here, we will name it "pic2". (For more, just use "pic3", "pic4", and so on). Then just link it to another page: Now you will have two changing images linking to different places! Do this for as many image links as you wish.....it can add a nice impact to your page for those with newer browsers. So, you want your script to change a different image when you place your mouse on the first one, or maybe when you place your mouse on a link. Check out the images below. Place your mouse over the top one, and watch the bottom image change! We are going to see how to do that using the hover button script from the first rollover tutorial, but adding a few modifications. You will need to be familiar with the first hover button tutorial before you proceed. To get started, let me put up this new version of the script. This time, we are going to use Object Detection instead of browser detection. This will make the script a bit shorter and easier to use. Here is the script, read through it and see if you can catch the trick that changes a different image than the one the mouse goes over:

So, did you see the trick? Don't worry, if you didn't we'll get to it in no time. First, let's look at how the script gets started: Detection and Preloading You probably noticed our detection was quite a bit shorter using object detection. Rather than checking for NS3+ or IE4+ browsers, we were able to check for the document.images object: if (document.images) { .. } Once the that has been checked, we preload the images we need for the mouseover. Notice that we only preloaded the images for the second picture. This is the one we want to change, while the first one stays the same: if (document.images) { pic2on= new Image(100,25); pic2on.src="story2.gif"; pic2off= new Image(100,25); pic2off.src="story1.gif"; } Now we are ready for the functions. The Functions Actually, the functions remained unchanged, except that we used an object detection again in place of browser detection. function lightup(imgName) { if (document.images) { imgOn=eval(imgName + "on.src"); document[imgName].src= imgOn; } } function turnoff(imgName) { if (document.images) { imgOff=eval(imgName + "off.src"); document[imgName].src= imgOff; } } Everything else is the same, we just need to change one image on the mouseover. The trick to making it change a different image comes in the parameter we are going to send the function when we call it. So, on to the HTML code, where we will call the functions. The HTML: Calling the Functions Now, we get to the point where we call the functions with the onMouseover and onMouseout commands. We do this when the mouse is over the first image, which we will use as a link to "newpage.html". It could link to anything you want, or nothing at all- but you will need the link tag to call the onMouseover and onMouseout commands. Here is the HTML:

Now, notice that the first image is named "pic1", in the name="pic1" attribute of the image tag. The image we want to change is the one below it (the second image tag), which is named "pic2" using name="pic2" in the image tag. Now, look at the link tag that is used for the first image. When it uses the onMouseover command, look at the parameter to the function call: onMouseover="lightup('pic2')" Yes, it is telling the function to change 'pic2', which is the other image below it! So, the function performs the work on the second image, and leaves the first image as merely a link, a link that changes the second image while the mouse is over it. The onMouseout command does the same thing, just in reverse. It changes the second image back to normal. What about a Plain Link? To use a regular link to change the image, just remove the first image tag in the HTML, and replace it with text, like this: New Page

Now, you get something that looks like this: New Page This script could be used to display a graphic with text while the mouse is on another image- the graphic could describe where the link will go when it is followed. You could also make some other nifty effects, try it out and see what you can come up with! Well, how do you go about changing more than one image at a time? Maybe you want the image the mouse is over to change and have another change at the same time. Here is an example below. Move your mouse over the top image, and both images change! This comes from the same script we have been using in the previous rollover tutorials. You will need to be familiar with JS Hover Buttons and JS Hover Buttons 2 before you proceed. Now, this script will also use Object Detection like we did in the previous section. This time, we want to change both images when the mouse is over the top one. Again, I'll start by giving you the complete script for this trick. See if you can catch the changes that make the script change more than one image at a time:


Well, did you see what we did? Yes, the functions changed. Each function now takes two parameters. Also, when we call the functions from our HTML code, we call them with two parameters. The Functions Let's take a look at the lightup() function: function lightup(imgName,imgName2) { if (document.images) { imgOn=eval(imgName + "on.src"); document[imgName].src= imgOn; imgOn2=eval(imgName2 + "on.src"); document[imgName2].src= imgOn2; } } The function takes in two variables from the outside (parameters). It takes in imgName and imgName2. These will correspond to the names of the images, pic1 and pic2. So, the value of imgName is "pic1" and the value of imgName2 is "pic2". Now, you will see the code we used to change a single image before: imgOn=eval(imgName + "on.src"); document[imgName].src= imgOn; Those two lines change our first image (pic1). Now look at the next two lines. Yes, they are identical- except we changed the variable names by adding a 2 on the end of them. This way, the code works on imgName2, which is "pic2", the name of our second image. These lines are what changes the second image: imgOn2=eval(imgName2 + "on.src"); document[imgName2].src= imgOn2; Nice, isn't it? The turnoff() function does exactly the same thing in reverse. It switches the images back to normal. The HTML Now, we have to call the functions from our link tag around the first image. We use the onMouseover and onMouseout commands for the function calls:
Let's look at the call from the onMouseover command: onMouseover="lightup('pic1','pic2')" Notice that it calls the function with two parameters. The first is the name of the top image, "pic1". The second parameter is the name of the bottom image, "pic2" (in the name="pic2" attribute). This allows the function to change both images while the mouse is over the top one. The onMouseout command calls the turnoff() function with the same parameters, so the images change back when the mouse goes away. Can I do 3 or More? Yes, just add an extra two lines to both functions like we did above for each additional image, changing the variable names- by adding a 3, 4 and so on- to the end of the variable names. You will also need to add an extra parameter to both functions, and to both function calls in the HTML. So, if you use the script to change 3 images, you would change both of these functions like this: function lightup(imgName,imgName2,imgName3) { if (document.images) { imgOn=eval(imgName + "on.src"); document[imgName].src= imgOn; imgOn2=eval(imgName2 + "on.src"); document[imgName2].src= imgOn2; imgOn3=eval(imgName3 + "on.src"); document[imgName3].src= imgOn3; } } function turnoff(imgName,imgName2,imgName3) { if (document.images) { imgOff=eval(imgName + "off.src"); document[imgName].src= imgOff; imgOff2=eval(imgName2 + "off.src"); document[imgName2].src= imgOff2; imgOff3=eval(imgName3 + "off.src"); document[imgName3].src= imgOff3; } } Also, don't forget to preload the new images with the others at the beginning of the script. Just add the new image like you did for the others. Then, you have to change the function calls, and add the extra image to your HTML code:

Well, try it with 50 images or so- maybe you can drive yourself insane looking for syntax errors through 50 images! Well..maybe not. See what you can come up with, and have fun with multiple rollovers! Now that we have changed images in all sorts of other ways, we are left with: "How to change one image to various other images when a viewer runs the mouse over a set of links or linked images". A long explanation, but the script for this is the shortest rollover script we have written yet. Of course, we are going to make a couple of adjustments that we didn't make in the earlier scripts in order to condense the code a bit. First, let's look at an example of what I was tryng to say in that long quote at the beginning. A visual has to be better than that quote I wrote, right? Here it is, place your mouse over some of the links below and watch the image change accordingly: Noise Yellow Big Face Seeing Spots This comes from the same script we have been using in the previous rollover tutorials. You should be familiar with JS Hover Buttons and JS Hover Buttons 2 as they help explain the basics about the preloading and such. This script will also use Object Detection like we did in the previous sections. The HEAD Section Code Now that we have the example, we need some code to see how this thing works. Let's start by looking at the code for the HEAD section of the page, here it is: Pretty short in comparison to our previous rollover scripts, isn't it? The preloading is basically the same. However, rather than adding "on.src" at the end of the image location definitions, we simply add .src to it. This is one are where we shorten the coding a bit. Since the image is "on" anytime a link is hovered, the "on" bit would not serve as a helpful hint here. We do have one named image_off, since this would be the default image and might help. The other images are just given a different number like "image2", "image3" and so on. These changes will make more sense as we look at the function. The function begins by taking two parameters (yes, parameters agian!). The first is the name of the image in your image tag, where you write your name="name" attribute (In this script, the name is pic1, see the IMG tag in the BODY code below). The second parameter is the name of the image object that will replace the default (off) image when the mouse moves over the link. After that, we detect the image object. Then, we use the parameters to change the default image. imgOn=eval(imgName + ".src"); This takes the image name and adds the .src to it so the script finds the location of the replacement image. It assigns that url to the imgOn variable. document[picName].src= imgOn; This actually changes the image. You'll see the picName variable is used, so that the image name sent into that variable (pic1 for this script) is changed to the replacement image. The turnoff() function used on the onMouseout event in the previous scripts was repetitive. It did the same thing as the lightup function, but on the onMouseout event. It was used for clarification, but now we can just use this single change1() function for the onMouseover and onMouseout events to condense the code further. This helped shorten the code quite a bit here. The BODY Section Code This is where the functions are called and the parameters are set. Here is the code, (preformatted):

Noise    Yellow    Big Face    Seeing Spots

Just change the urls and text to your own choices. Then, you'll see that all the onMouseout calls are the same. You will want your onMouseout calls to be the same too (not necessarily exactly like this one, but they should all match each other). The onMouseout command calls the default image object you defined while preloading. Ours was named "image_off". The calls made onMouseover only change the second parameter. It is changed to one of the replacement image objects you defined while preloading. Just choose the one that fits with your link. Finally, be sure the name="name" attribute in the IMG tag matches the first parameter you send to the function in each case. Ours was pic1, but you may choose another name-- just be sure to change the function calls to match it. You'll notice that the pic1 parameter didn't change in any of the function calls, so you may wonder why we should bother with the parameter and just use pic1 in the function itself. The reason is so you could use this function for more than one image/link set on the page. Just be sure to give the other image(s) a new name in the IMG tag in the name="name" attribute. For instance, the second one could have name="pic2". You could then call the function by replacing all the pic1 parameters with pic2, and now the first parameter has a use. Then again, the use of it just depends on how many times you want to use the effect on a single page. Do you remember the browser detection script we worked on a while back? Then you probably remember how much trouble it was to detect a specific browser type before we could run certain scripts. Here was how we had to do it: browserName=navigator.appName; browserVer=parseInt(navigator.appVersion); if ((browserName=="Netscape" && browserVer>=3) || (browserName=="Microsoft Internet Explorer" && browserVer>=4)) version="n3"; else version="n2"; That is a lot of code to run through, and it can be much worse when you create a script that has a lot of browser differences. Well, instead of checking for the browser, we could have checked for the javascript object that we needed for the script to work. Since we know that a hover button script needs the document.images object to work, we could shorten the above code to say: if (document.images) { ...code...} In fact, this object just so happens to exist in the browsers we checked for, and not in the browsers that were excluded. So, using this object detection code, we are checking for Netscape 3 or higher, and MS Internet Explorer 4 or higher! And as a bonus, if any other browser happens to recognize the document.images object, the script will run for them too! (Opera perhaps?) You can also use a couple of the new objects to check for version 4 browsers. If you are looking only for NS4 or better, check for the document.layers object: if (document.layers) { ...code...} If you want only IE4 or better, check for the document.all object. (May change when NS5 arrives): if (document.all) { ...code...} Of course, if you just want it to work for either version 4 browser, check to see if the browser has one object or the other: if (document.all || document.layers) { ...code...} You can find some more uses for this as you are coding, so that you can avoid those pesky javascript errors in older browsers. While you are at it, it will probably keep away those errors with the newer browsers as well. JavaScript and Frames. Frames and JavaScript. Sounds like a mess doesn't it? Well, it does make things a bit more complicated. Let's see if we can figure out how to get those frames to work with our scripts. The first thing you will want to know is "How in the land of JavaScript do I access javascript variables and other things in one frame from another frame? The answer is to use a trick like this: parent.framename.attributes_to_change Replacing framename with the name you gave the frame in your frameset, ie: In this case, you would access something in that frame with: parent.right_frame.attributes_to_change Let's start by changing the value of a text box in a frame on the right from a frame on the left side. First, set up a little frameset. This will require 3 separate html pages. Your frameset, and the html for your 2 frames. Let's begin with the frameset: Frames Values

Hosted by www.Geocities.ws

The two pages I will use inside the frameset are "jex13.htm" and "jex14.htm". The left side (jex13.htm) will have this html code: JavaScript Example 13
Hosted by www.Geocities.ws

This is where we use our new command, inside the onClick=" " command: onClick="parent.right_frame.document.form1.text1.value='Me!'" As you can see, we access the right frame with the "parent.right_frame." and then we add what we want to change onto the end. Since we want to change something inside the document object, we have to use "parent.right_frame.document.". If you leave out the "document" the browser defaults to using the "window" object, which we will use later on. But for now, we want the "document" object. Now, to access the form, we tack on the name of the form, "parent.right_frame.document.form1.". Then, we access the textbox by adding the name of the textbox onto it: "parent.right_frame.document.form1.text1.". Finally, we can access the value attribute of the textbox by placing value at the end, and assigning it a value with the eqaul sign: "parent.right_frame.document.form1.text1.value='Me!'" So, we now have a button that will change a textbox in the right_frame. The html code for the right frame (jex14.htm) is simply a form with an empty textbox: JavaScript Example 14
Hosted by www.Geocities.ws

Now, you can see an exaple of our....well...master frames script: You want to change more than one frame at a time? OK, well here is how to do make the trick work for you! The first thing you will need is a frameset to get you started. Again, I will use a frameset with two frames. Here is the code for the frameset page: Frames Example 5
Hosted by www.Geocities.ws

Be sure you give each frame a name using the name=" " attribute. I named the frames above "left_frame" and "right_frame". Now, create html files for each frame you will need to use. Since I have two frames, and want to change both frames at once, I need 4 html files. I called mine "page1.htm", "page2.htm", "page3.htm", and "page4.htm". Now, since I am using the left frame for my navigation, that is where I am going to put the link to change the two frames. The html page for the right frame does not need to be modified at all, unless you just want to.... Edit the Left Frame HTML Now, to make this work, we need to edit the html page that makes the left frame. In this case, the left frame is "page1.htm". So this is the file we need to work on. Here is what we need to have in the html code to get the link to change multiple frames: FRAME 10
Click the link below to change both frames.
Change 2 Frames
Hosted by www.Geocities.ws

The JavaScript Function Don't worry, it isn't as bad as it seems. The important lines are: parent.left_frame.location="page3.htm"; parent.right_frame.location="page4.htm"; That is where you tell the browser what html pages you want to change both frames to, and where you use the frame names we gave our frames earlier. In general, it would look like this: parent.your_frame_name.location="url"; parent.your_other_frame_name.location="url"; Replace your_frame_name with the name of your frame from earlier. Replace url with the web address of the page you want to change to. Mine was named "left_frame", and I wanted to change the page to "page3.htm", so I got the line: parent.left_frame.location="page3.htm"; Do the same for the second frame. My other frame was named "right_frame" and I wanted to change to "page4.htm": parent.right_frame.location="page4.htm"; That's the only part of the script you really have to edit. If you used the same names and pages I did, you didn't need to edit at all. As far as the url goes, you can also use a full url if the page you want to link to is not in your directory. You could have something like this: parent.left_frame.location="http://www.someplace.com/somepage.htm"; What's With the Link Tag? Change 2 Frames You probably also noticed that the link tag does not link to a normal url. This is because it is calling our javascript function, which is what we are using to change the urls. This is why we can change two at the same time. If you want more information on how the javascript link works, see the JavaScript Link Tutorial.. Give it a Try To see the code in action, click the link below for a sample page: Example Page In the example, you probably saw that I had a link to change the frames back again. If you want to add a link like that, you will need to edit the second left frame's html code. In my example, it would be "page3.htm" that you would need to edit. You can add the same script and code, but change the urls in the javascrpt function to lead back to your first two frames. I wanted to go back to "page1.htm" and "page2.htm". My example code for the url change looked like this: parent.left_frame.location="page1.htm"; parent.right_frame.location="page2.htm"; Now, give it a try yourself. If you are using frames, this may be a handy trick for you sometime. You can do many things with javascript using your forms. Great, you say, but where does one figure out how to access those form elements with javascript? Well, if I were in a good mood, I might tell you! .....Oh, all right, I'll tell you anyway........... You can access various parts of a form by naming them. In turn, you must give the form a name, because it will be part of what you need to get to what you want. Take a look at the following form code:
This code creates a little input box for text. The value="I am Cool!!!" attribute gave this box an initial value, which can be changed if the viewer types something else.....OR..... if you were to change it with javascript! Here is what the box looks like: You can go up there and type something else if you like......just keep it clean, OK? :-) Now, recall from the code above that we gave this form and the box names. This is how we will get to them with javascript. Now, the input box is part of the form, and the form is part of the document. If you remember the document.location object from a previous section, you know we can access parts of the document and change them. (document.location allowed us to change the url and go to a different page). So, to access the form, we would use: document.coolform Remember, the name of our form is "coolform" from the name="coolform" attribute inside the form tag. Now, to access the text box, you would add on the name of the text box: document.coolform.cooltext Again, the name of the text box was used. We had named it "cooltext". Now, we can access the value of the text box, which is what is in the value=" " attribute. So, if we wanted to get to the value of the box....the text "I'm Cool!!!", we would add the word "value" to the end of the list: document.coolform.cooltext.value Notice that each time we add something to the list, it is separated from the others by a dot. This is because we are using "objects" to get what we need. The document, the form, and the text box are all objects in the browser. The addition of the "value" at the end lets us access the value of the text box object. The text box object was part of the form object, and the form object......yes, it is part of the document object! Now that we can get to the value of the text box, we should be able to do something with it, right?.... Getting the idea? Yes, let's try to change the text in the box! One way to do this is to let the viewer click a button and change the text when the button is clicked. For the above form, we can simply add a button at the end, and use the old "onClick" function to perform a javascript. Here is the sample code:
  
Notice that I gave this form a new name (coolform1). If you have more than one form on the same page, be sure they all have different names. Otherwise when you try to access the form, the browser won't know which form you want to go to, because they have the same name! So....... This gives you the following box and button. If you are feeling rather cool today, click on the button to change the text in the text box.... You can also change the text on a button that is clicked in the same way:
Be sure to make the initial set of text in the value=" " attribute longer than the text you want to change it to. The button will need the room to write your new text! Try out the button below: So, you have been thinking about adding a drop box for people to navigate your page with. One problem.....how is it done? Below is a sample navigation drop box. Choose a page, and click the "Go!" button. You will be taken to the page you asked for. (Both are kind of boring by the way). Give it a try below: Page 1My Cool Page For this drop box to do this, we must use a javascript that will access the Select Box and then go to the new destination. In the last section, we learned how to access the value attributes of a text box and a button. We can access the Select Box in the same way. Below is the code used for the drop down box:
  
Notice that we gave the form and the select box a name. These are used later to access the value attribute of the Select box. (If you scrolled out to read all of that, you saw it got pretty messy there). We also gave the value=" " attribute to each OPTION tag. You will notice the values are urls. The url is where we want the browser to go when the user selects that option. So, for the first option,