How to display link from content div into main div
The below line opens a selected index from a drop down in a browser window. The form field is in a div called "contents". I need to know the syntax needed to open this selection in another div on the same page called "main". The "_top" location opens the file in a new window. I want to open this on the same page. Do I need javascript for this?
Code:
onchange="window.open(this.options[this.selectedIndex].value,'_top')" style="text-align: center">
Here is all the code for my file:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<style type="text/css">
.banner {
background-color: #000000;
width: 100%;
height: 25px;
}
.contents {
width: 180px;
height: 560px;
background-color: #0000FF;
}
.main {
width: 100%;
height: 100%;
background-color: #006600;
}
</style>
</head>
<body>
<div id="banner" class="banner">
</div>
<div id="contents" class="contents">
<form action="../">
<br />
<select onchange="window.open(this.options[this.selectedIndex].value,'_blank')" style="text-align: center">
<option value="">Choose a destination...</option>
<option value="http://www.directpaintsaleswa.com/brianschmit/WXRECORDS/images/yearly/Portland1981-2010.png">CLIMATE</option>
<option value="http://www.directpaintsaleswa.com/brianschmit/WXRECORDS/images/yearly/2011.png">2011</option>
<option value="http://www.altavista.com/">ALTAVISTA</option>
<option value="http://www.amazon.com/">AMAZON</option>
<option value="http://artlung.com/">ARTLUNG</option>
</select>
</form>
</div>
<div id="main" class="main" style="position: absolute; width: 1148px; height: 564px; z-index: 1; top: 43px; left: 192px">
</div>
</body>
</html>
Why don't you use innerHTML property???
"It will never rain roses: when we want to have more roses, we must plant more roses."
- George Eliot
First of all, yes, you'll need some JavaScript to do this, as you're doing now. Second, I would suggest that you use an <iframe> to hold the contents of the newly opened page.
Code:
<script type="text/javascript">
function showPage(theControl) {
theURL = theControl[selectedIndex].value;
document.getElementById('myFrame').src = theURL;
}
</script>
<select onchange="showPage(this);" style="text-align: center">
and then for your DIV:
Code:
<div id="main" class="main" style="position: absolute; width: 1148px; height: 564px; z-index: 1; top: 43px; left: 192px">
<iframe id="myFrame" src="" width="100%" height="100%" frameborder="0" scrolling="yes"></iframe>
</div>
You'll probably have to adjust the attributes in the <iframe> tag a bit, but it should be close. And you're likely to have problems getting the "main" <div> to fit nicely on a page with any other content, but...
Rick Trethewey
Rainbo Design
I am getting an error in Firebug. It says "selected index is not defined" on line #28. Forgive me in advance for being a beginner here. Here is my current code.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<style type="text/css">
.banner {
background-color: #000000;
width: 100%;
height: 25px;
}
.contents {
width: 180px;
height: 560px;
background-color: #0000FF;
color: #FFFFFF;
}
.main {
width: 100%;
height: 100%;
background-color: #006600;
}
</style>
<script type="text/javascript">
function showPage(theControl) {
theURL = theControl[selectedIndex].value;
document.getElementById('myFrame').src = theURL;
}
</script>
</head>
<body>
<div id="banner" class="banner">
</div>
<div id="contents" class="contents">
<form action="../">
<br />
<select onchange="showPage(this);" style="text-align: center">
<option value="">Choose a destination...</option>
<option value="http://www.directpaintsaleswa.com/brianschmit/WXRECORDS/images/yearly/Portland1981-2010.png">CLIMATE</option>
<option value="http://www.directpaintsaleswa.com/brianschmit/WXRECORDS/images/yearly/2011.png">2011</option>
<option value="http://www.altavista.com/">ALTAVISTA</option>
<option value="http://www.amazon.com/">AMAZON</option>
<option value="http://artlung.com/">ARTLUNG</option>
</select>
<br />
<br />
<br />
<br />
</form>
</div>
<div id="main" class="main" style="position: absolute; width: 1148px; height: 564px; z-index: 1; top: 43px; left: 192px">
<iframe id="myFrame" src="" width="100%" height="100%" frameborder="0" scrolling="yes"></iframe>
</div>
</body>
</html>
I dont know how to capture the selected option in the drop down and send the URL to the iframe.. Thank You!
Sorry. I wrote that on the fly. Try:
Code:
<script type="text/javascript">
function showPage(theControl) {
theURL = theControl[theControl.selectedIndex].value;
document.getElementById('myFrame').src = theURL;
}
</script>
<select onchange="showPage(this);" style="text-align: center">
Rick Trethewey
Rainbo Design
Rick...you are AWESOME!!! Thank you so much
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks