Changing the Url of an Iframe with a selection box

J

john.dickeson

Hello
I have been wrestling with a problem, I am trying to change the url of
an Iframe from a simple selection box, once the user selects the
desired url they wish to visit from the main page the iframe then loads
the url while not affecting the main page. I am using the onchange
event of the select tag to drive the javascript function hopefully
passing the value of the selection wich in this case is the url to the
independant script wich will in turn will change the src of the iframe
from the default page that is loaded when first viewing the page.One
question I have is would it be better to use the onload event to set
the initial src then use the onchange event form the select to change
the src or staticly set the src then use the onchange event to change
it? below is an example of my code so far. Also currently whenever I
try to pass teh value to the script I get an object expected error and
nothing happens.Bear in mind I know enough C++ to make myself dangerous
and can stay on top javascript to a point but right now I am just lost.
just need a nudge in the right direction at this point please :D

<select name="sites" id="sites" onchange="changesite()">
<option value=" "> </option>
<option value="http://www.nanpa.org">NANPA.org</option>
<option value="http://www.google.com">Google.com</option>
<option
value="http://www.spywarewarrior.com">spywarewarrior.com</option>
</select>

Function changesite(value)
{
var newsite = value;
document.frames['websites'].src = newsite;
}
 
J

Jim

John,
This should work for you:
<body bgcolor="#FFFFFF" text="#000000">
<form name="selection">
<select name="sites" id="sites"
onchange="document.frames['websites'].location=this.value">
<option selected>Pick a Site</option>
<option value="http://www.yahoo.com">Yahoo.com</option>
<option value="http://www.google.com">Google.com</option>
<option value="http://www.ebay.com">Ebay.com</option>
</select>
</form>
<hr>
<iframe name="websites" id="websites" width="80%" height="60%"
src="http://www.ask.com" scrolling="yes"></iframe>
</body>
 
J

john.dickeson

Thnx for the heads up, I had though along those lines but had dismissed
it since I was focusing ont he script and making it harder for myself
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top