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="[this.selectedIndex].value,'targetIFRAME');this.selectedIndex=0;">
    <option>Choose A View</option>
    <option value="">Vid01</option>
    <option value="">Vid02</option>
    <option value="">Vid03</option>
    <option value="">Vid04</option>
    <option value="">Vid05</option>
    <option value="">Vid06</option>
    <option value="">Vid07</option>
    <option value="">Vid08</option>
    <option value="">Vid09</option>
    <option value="">Vid10</option>

<iframe src="" 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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 ?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
try this way

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

<iframe src="" 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

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!
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?
goodie069Author Commented:
Browser issue. Thanks to both of you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.