Click to See Complete Forum and Search --> : iframe src


obviousunknown
07-11-2003, 07:38 PM
I'm not exactally sure how to this but, I'm looking for a way to change the source of an iframe, by selection of an option box. A link would work too, but I'd prefer the first way.

Thanks in advance.

micjohnson
07-11-2003, 10:58 PM
<SCRIPT language=JavaScript>
var i=null
function go (){
if (i != null){}
y=i;
document.getElementById('1').innerHTML = '<iframe src="+y+"></iframe>'
}
</SCRIPT>

put that in your head

<div id=1></div>
put that in your body where you want the iframe to be when it is chosen

add the the code of your option i=("http://www.thesiteyouwant.com")

Charles
07-12-2003, 06:23 AM
JavaScript will fail for 13% of users leaving you looking awfully silly with broken navigation on your site. And there's no need to use JavaScript here.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example</title>
<div><iframe name="spec" src="http://www.w3.org/"></iframe></div>
<div><a href="http://www.w3.org/TR/html401/" target="spec">HTML 4.01</a> | <a href="http://www.w3.org/TR/xhtml1/" target="spec">XHTML 1.0</a> | <a href="http://www.w3.org/TR/xhtml11/" target="spec">XHTML 1.1</a></div>

obviousunknown
07-12-2003, 02:05 PM
I've got this for the script in the head:
<script>
go(source)
{
document.getElementById("ifrm").src = source;
}
</script>

Then i have this in the body:
<iframe src="" id="ifrm">
<a href="javascript:go('http://www.yahoo.com');">Yahoo!</a>
<a href="javascript:go('http://www.google.com');">Google</a>

-------
How would I do the same effect, but using an option box instead of a link? Something like this?

<select>
<option onClick="javascript:go('http//www.yahoo.com');">Yahoo!</option>
<option onClick="javascript:go('http//www.google.com');">Google</option>
</select>

Charles
07-12-2003, 02:36 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<form action="cgi-bin/url.pl" target="spec">
<div>
<select name="url.pl">
<option value="http://www.w3.org/TR/html4/">HTML 4.01</option>
<option value="http://www.w3.org/TR/xhtml1/">XHTML 1.0</option>
<option value="http://www.w3.org/TR/xhtml11/">XHTML 1.1</option>
</select>
<button type="submit">Send me</button>
</div>
</form>

And the Perl script url.pl would look something like:

#!user/local/bin/perl
use CGI qw(redirect param);
print redirect param 'url';

obviousunknown
07-12-2003, 09:24 PM
cgi, nevermind, I'll fool around with different ideas. thanks though.