Open links chosen from Select/DropDown menu in iFrame within page

I have a static webpage that contains an second page embedded via an iFrame.

I would like to load content into this iFrame via user selection (URL) through a drop down menu at the top of the main page.

The code I am including DOES work, but only for the first selection. After the first page is loaded into the iFrame, if the user tries to select another option from the dropdown, that page will open in a new window and not the iframe. The main page has to be refreshed in order for it to open another link in the iframe.

I'm not tied to this code -- if someone has a better solution with javascript or php, etc, please let me know. I've tried a few solutions today and this one was the closest to achieving the desired functionality.

The only other feature I require (that this script provides correctly) is an auto-submit of the form when the user clicks their selection. I don't want a submit or go button.

Thanks in advance for any suggestions. Here's the code:

<form action="../">
<select onchange="window.open(this.options[this.selectedIndex].value,'targetIFRAME');this.selectedIndex=0;">
    <option>Choose A View</option>
    <option value="http://www.mydomain.net/collaborate/page.html?file=Vid01-full.flv">Vid01</option>
    <option value="http://www.mydomain.net/collaborate/page.html?file=Vid02-full.flv">Vid02</option>
    <option value="http://www.mydomain.net/collaborate/page.html?file=Vid03-full.flv">Vid03</option>
    <option value="http://www.mydomain.net/collaborate/page.html?file=Vid04-full.flv">Vid04</option>
    <option value="http://www.mydomain.net/collaborate/page.html?file=Vid05-full.flv">Vid05</option>
    <option value="http://www.mydomain.net/collaborate/page.html?file=Vid06-full.flv">Vid06</option>
    <option value="http://www.mydomain.net/collaborate/page.html?file=Vid07-full.flv">Vid07</option>
    <option value="http://www.mydomain.net/collaborate/page.html?file=Vid08-full.flv">Vid08</option>
    <option value="http://www.mydomain.net/collaborate/page.html?file=Vid09-full.flv">Vid09</option>
    <option value="http://www.mydomain.net/collaborate/page.html?file=Vid10-full.flv">Vid10</option>
</select>
</form>

<iframe src="http://www.mydomain.net/collaborate/blank.html" name="targetIFRAME" id="targetIFRAME" frameborder="0" height="900" width="800">You need a Frames Capable browser to view this content.</iframe>

Open in new window

goodie069Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
remorinaConnect With a Mentor Commented:
Hi goodie069,
Your code seems to work correctly, I've tried your code on FF, IE8 & IE7 and they all seem to work fine and load the URL in the iframe, none opened a new window so far, I've also tried changing the websites and values and they worked.

What browser are you using ?
0
 
kadabaConnect With a Mentor Commented:
try this way

<html>
<head>
<script type="text/javascript">
function loadFrame(url,frameId){
	document.getElementById(frameId).src = url;
}
</script>
</head>
<body>
<form action="javascript:void(0);">
<select onchange="loadFrame(this.value,'targetIFRAME');this.selectedIndex=0;">
    <option>Choose URL</option>
    <option value="http://www.google.com">google</option>
	<option value="http://www.yahoo.com">yahoo</option>
	<option value="http://www.youtube.com">youtube</option>
	
</select>
</form>

<iframe src="http://www.bing.com" name="targetIFRAME" id="targetIFRAME" frameborder="0" height="900" width="800">You need a Frames Capable browser to view this content.</iframe>
</body>
</html>

Open in new window

0
 
goodie069Author Commented:
Looks like it was a browser issue. I was using Safari - which is still opening subsequent links in a new window - but it's working correctly under Firefox and IE.

Thanks for checking, Remorina.

I'll give that code a try, Kadaba - thanks!
0
 
remorinaCommented:
I've also tried it now on Safari 4.0.5 for windows, and it still works well without opening new windows.

Possibly something wrong with your browser?
0
 
goodie069Author Commented:
Browser issue. Thanks to both of you!
0
All Courses

From novice to tech pro — start learning today.