Changing the Source in a Frame Using JavaScript

You are all familiar with using links in one frame to change the page that appears in a second frame. How can you have a script on a page contained in one frame change the page in another frame? To do this you need to realize that the window in a frame considers the main page with that frame its parent. The window contained in a frame can change the document appearing in another frame by setting parent.framename.location to the url of the new window. Here is the code for such a window.

<SCRIPT TYPE = "text/JavaScript">
<!--
function gotoit(val)
{
	if(val==0)
	    parent.MAIN.location="test0.htm";
	else
	    parent.MAIN.location="test1.htm";
}
//-->
</SCRIPT>

</HEAD>
<BODY TEXT=#FFFFFF  BGCOLOR=#0000A0 > 
<FORM ACTION="#" ><BR>
<SELECT NAME=item >
<OPTION VALUE=first> first
<OPTION VALUE=second> second
</SELECT><BR>
 <INPUT TYPE = "BUTTON" NAME=button VALUE="GoThere" onClick="gotoit(item.selectedIndex);" >

</FORM>

To get a copy of the pages using this code click here.