PDA

View Full Version : Loading into an iFrame


Gary Williams
11-10-2002, 05:00 PM
Using the following simple function, I can open a new window to display the one of the four htm files just by clicking on one of the four selections in the drop down box, named 'room'.

I want to change the function to load the chosen htm file into an 'iFrame' (named iFrame1) on the same page, rather than into a new window (or window popup).

Is there a command like 'iFrame.load' that can achieve this?

<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">

function loadiframe(){
var URL = document.choosingfan.room.options[document.choosingfan.room.selectedIndex].value;
window.open('../html/bedroom.htm','bedroom','width=400,height=250,left=350,top=200');
}
</SCRIPT>

</HEAD>

<BODY>
<FORM>

<SELECT ID="room" NAME="room" onChange="javascript:loadiframe()">
<OPTION VALUE="" SELECTED>Please Select</OPTION>
<OPTION VALUE="">-----------------</OPTION>
<OPTION VALUE="../html/bedroom.htm">Bedroom</OPTION>
<OPTION VALUE="../html/conservatory.htm">Conservatory</OPTION>
<OPTION VALUE="../html/lounge.htm">Lounge</OPTION>
<OPTION VALUE="../html/kitchen.htm">Kitchen</OPTION>
</SELECT>

<iFrame name="iFrame1" width="400" height="300" border="0" frameborder="0" scrolling=no marginwidth="0" marginheight="0" vspace="0" hspace="0"></iFrame>

</FORM>
</BODY>
</HTML>

Gary Williams
11-10-2002, 05:23 PM
Solved it, dead simple. Here's the script that works:

<SCRIPT LANGUAGE="JavaScript">

function loadiframe(){
var URL = document.choosingfan.room.options[document.choosingfan.room.selectedIndex].value;
iFrame1.location.href = URL;
}
</SCRIPT>