/    Sign up×
Community /Pin to ProfileBookmark

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”>[/CODE]

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=”../”>
&nbsp;&nbsp; <br />
&nbsp;
<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>
[/CODE]

to post a comment
HTML

5 Comments(s)

Copy linkTweet thisAlerts:
@TheAliveWinnerApr 27.2012 — Why don't you use [I][B]innerHTML[/B][/I] property???
Copy linkTweet thisAlerts:
@rtretheweyApr 27.2012 — 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.

<i>
</i>&lt;script type="text/javascript"&gt;

function showPage(theControl) {
theURL = theControl[selectedIndex].value;
document.getElementById('myFrame').src = theURL;
}
&lt;/script&gt;
&lt;select onchange="showPage(this);" style="text-align: center"&gt;

and then for your DIV:
<i>
</i>&lt;div id="main" class="main" style="position: absolute; width: 1148px; height: 564px; z-index: 1; top: 43px; left: 192px"&gt;
&lt;iframe id="myFrame" src="" width="100&amp;#37;" height="100%" frameborder="0" scrolling="yes"&gt;&lt;/iframe&gt;
&lt;/div&gt;

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...
Copy linkTweet thisAlerts:
@Schmit43authorApr 27.2012 — 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="../">
&nbsp;&nbsp; <br />
&nbsp;
<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>
[/CODE]


I dont know how to capture the selected option in the drop down and send the URL to the iframe.. Thank You!
Copy linkTweet thisAlerts:
@rtretheweyApr 28.2012 — Sorry. I wrote that on the fly. Try:
<i>
</i>&lt;script type="text/javascript"&gt;

function showPage(theControl) {
theURL = theControl[theControl.selectedIndex].value;
document.getElementById('myFrame').src = theURL;
}
&lt;/script&gt;
&lt;select onchange="showPage(this);" style="text-align: center"&gt;
Copy linkTweet thisAlerts:
@Schmit43authorApr 28.2012 — Rick...you are AWESOME!!! Thank you so much ?
×

Success!

Help @Schmit43 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...