Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6089979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:09:41+00:00 2026-05-23T12:09:41+00:00

Okay, so I’ve successfully completed my goal using buttons which was merely a test.

  • 0

Okay, so I’ve successfully completed my goal using buttons which was merely a test. My real goal is to dynamically change the innerHTML within a DIV, based on the option selected using the drop down menu. The catch however, is that it MUST be done using each menu items unique ID. It CANNOT work using the value of each menu item, as the value is being utilized by an entirely different script, which is working (for the moment).

I have a working example using buttons as well as a drop down menu, but the drop down menu only works in this example because I am using a separate function for each list option. When this goes live, I’ll have two drop down menus that will contain several dozen items, so writing a function for every item would be time consuming and not very practical for production.

Here is the working example:

<!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>
<title>sandbox 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
#content {
display: block;
width: 50%;
height: 300px;
border: 1px solid blue;
overflow: hidden;
margin-left: auto;
margin-right: auto;
}
</style>

</head>

<body>

<script type="text/javascript">

function innerHTML1()
{
document.getElementById('content').innerHTML = '<iframe src="http://www.google.ca" width="100%" height="100%" frameborder="no"></iframe>';
}

function innerHTML2()
{
document.getElementById('content').innerHTML = '<iframe src="http://www.msn.ca" width="100%" height="100%" frameborder="no"></iframe>';
}

</script>

<div id="content"></div><br />
<input type="button" onclick="innerHTML1()" value="open Google" />
<p>
<input type="button" onclick="innerHTML2()" value="open MSN" />
</p>
<p>
<select>
<option value="">select an option...</option>
<option value="" onClick="innerHTML1()">open Google</option>
<option value="" onClick="innerHTML2()">open MSN</option>
</select>
</p>


</body>
</html>

So the above example seems to do the job fine, but that’s because its using two functions, one for each menu time.

So here is what I have so far and is what I need help with:

<!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>
<title>sandbox 2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
#content {
display: block;
width: 50%;
height: 300px;
border: 1px solid blue;
overflow: hidden;
margin-left: auto;
margin-right: auto;
}
#contentarea {
display: block;
width: 50%;
height: 300px;
border: 1px solid blue;
overflow: hidden;
margin-left: auto;
margin-right: auto;
}
</head>
<body>
</style>
<script type="text/javascript">
function changeContent()
{
var newContent = document.getElementById('selection');

var ContentInfo = newContent.selectedIndex;
newContent.value = newContent.options[ContentInfo].id;

document.getElementById('content').innerHTML = newContent;
}
</script>
<div id="content"></div> 
<p>
<select id="selection" onchange="JavaScript:changeContent()">
<option value="" id="" selected="selected">Select a website to load in the DIV..</option>
<option value="Page1" id="Page1.html">Page1</option>
<option value="Page2" id="Page2.html">Page2</option>
<option value="Page3" id="Page3.html">Page3</option>
<option value="Page4" id="Page4.html">Page4</option>
</select>
</p>
<p>
<script language="JavaScript" type="text/javascript">
<!--
function showSelected()
{
var PageList = document.getElementById('Pages');
var displayPage = document.getElementById('contentarea');

var NewPage = PageList.selectedIndex;
displayPage.value = PageList.options[NewPage].id;
document.getElementById('contentarea').innerHTML = displayPage;
}
//-->
</script>
<select id="Pages" onchange="showSelected()";>
<option selected="selected" value="" id="">Select a website to load in the DIV..</option>
<option value="" id="Page1.html">Page 1</option>
<option value="" id="Page2.html">Page 2</option>
<option value="" id="Page3.html">Page 3</option>
<option value="" id="Page4.html">Page 4</option>
</select>
</p>
<div id="contentarea"></div>
</body>
</html>

First thing to point out is that I tried writing the script in 2 different methods, both presenting their own unique error. I don’t know which one is closer to the correct answer or not so I’m presenting both in my question. The top DIV window shows [object HTMLSelectElement] and the items in the drop down menu disappear. The bottom DIV window shows [object HTMLDivElement], but the drop down menu seems unharmed.

Second thing to point out is that I’m a complete javascript newb. (in case you haven’t noticed already)

Third thing to point out is that I already realize that this is not going to work by simply entering the <iframe> tags in the ID section of every <option> and even if it did, that wouldn’t be very practical either. In the script I want to add something like:

<script language="JavaScript" type="text/javascript">
<!--
function showSelected()
{
var PageList = document.getElementById('Pages');
var displayPage = document.getElementById('contentarea');

var NewPage = PageList.selectedIndex;
displayPage.value = PageList.options[NewPage].id;
document.getElementById('contentarea').innerHTML = displayPage;

innerHTML = '<iframe src="+ displayPage +" width="100%" height="100%" frameborder="no"></iframe>';

}
//-->
</script>

…or something like that. So again…

-I'm loading an iFrame inside a DIV.
-The content of the DIV will change depending on what item in a dropdown menu is selected (must execute using onChange)
-The value of the `<option>` cannot be used for this solution, as value is being used for another script. The script must work using the id of each `<option>`
-Writing a seperate function for every `<option>` works, but isn't very practical.
-I fail at javascript ;)

Thanks very much in advance for any help you can offer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:09:42+00:00Added an answer on May 23, 2026 at 12:09 pm

    One way to do it is to combine your original code that added the iframe as a string, with your new code that gets the value from the select, and set the string dynamically. Note that your select’s onchange can pass a reference to the select to the function, to save you having to use document.getElementById(), something like this:

    <script>
    function showSelected(sel) {
       srcLocation = sel.options(sel.selectedIndex).value;
       if (srcLocation != "") {
          document.getElementById('content').innerHTML = '<iframe src="' + srcLocation +
              '" width="100%" height="100%" frameborder="no"></iframe>'; 
       }
    }
    </script>
    
    <select onchange="showSelected(this);">
       <option value="">select an option...</option>
       <option value="Page1.html">Page 1</option> 
       <option value="Page2.html">Page 2</option> 
       <option value="Page3.html">Page 3</option> 
    </select>
    

    Note that I’ve put the page names in the options’ value attributes rather than in id.

    EDIT: just remembered you specifically didn’t want to use value for some reason. What I’ve posted would work the same with id. Or you could pull that data out of the markup and just have it in code, something like this:

    <script>
    function showSelected(sel) {
       locations = ["",
                    "Page1.html",
                    "Page2.html",
                    //etc.
                   ];
    
       srcLocation = locations[sel.selectedIndex];
       if (srcLocation != undefined && srcLocation != "") {
          document.getElementById('content').innerHTML = '<iframe src="' + srcLocation +
              '" width="100%" height="100%" frameborder="no"></iframe>'; 
       }
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I'm running a small test webserver on my private network. I've got
Okay, so I'm doing my first foray into using the ADO.NET Entity Framework. My
Okay, I'm reading about Linux kernel development and there are some code snippets using
Okay, simple situation: I'm writing a simple console application which connects to a SOAP
Okay im making a mobile application using jquery, and then im using phonegap to
Okay I have a list of devices where i can select which to edit.
Okay I am having some problems with being able to change bitmaps when a
Okay, I've looked all over the internet for a good solution to get PHP
Okay so im working on this php image upload system but for some reason
Okay, here's the scenario. I have a utility that processes tons of records, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.