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

  • SEARCH
  • Home
  • 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 4037616
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:22:13+00:00 2026-05-20T12:22:13+00:00

I have a webpage in which I have a div that I would like

  • 0

I have a webpage in which I have a div that I would like to repopulate.
For now the content of that div is generated with Javascript the following way:

function foo(array){
    for(i=1;i<=maxIndex;i+=1){
        document.write ("<label><input type='checkbox'/>" + array[i] + "\n </label><br />")
    }
}

and I populate the div the following way:

        <div class="bla">
        blablabla
        </div>

        <div class="myDiv" id="myDiv">
            <form name="myForm">
            <script type="text/javascript">
                foo(myArray);
            </script>
            </form>
        </div>

        <div class="blah">
             blahblahblah
             <form>
             <select onchange="updateDiv(myArray)">
                          <option value="1"> Test1 </option>
                          <option value="2"> Test2 </option>
                          <option value="3"> Test3 </option> 
             </select>
             </form>
        </div>

The reason that I would like to repopulate the div is because I would like
it to be possible for the user to choose the arrangement of the content of the div
(i.e. when the user selects a certain item from a combobox, ‘myArray’
is re-sorted and then myDiv is repopulated such that the content now appears in a different order).

function updateDiv(array){
     array.sort();
     document.getElementById('myDiv').innerHTML = '<form name="myForm"><script type="text/javascript"> foo(myArray); </script></form>';

}

The problem that I am encountering is that I cannot manage to target the new
content in myDiv when the user selects the combobox.

I have tried using innerhtml, but the new content, which is outputted correctly, shows up in a completely new page instead of showing up in myDiv because of the JavaScript.

EDIT: It seems that now the problem is that innerhtml updates the code in the correct div (at least when I inspect it with firebug) but no text shows up (the JavaScript hasn’t been run…?).

I looked around online and did not seem to find an appropriate solution.

It would be greatly appreciated if someone could point me in the right direction or let me
know if I am approaching this completely wrong.

Thank you

  • 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-20T12:22:14+00:00Added an answer on May 20, 2026 at 12:22 pm

    Ok I finally figure out where the problem was: I should not have used so many document.write(), which outputs on a new page.

    Instead I store everything in a string and then use document.write() only in the last step, the following way:

    var astring;
    
    function foo(array){
        for(i=1;i<array.length;i+=1){
            astring += "<label><input type='checkbox'/>" + array[i] + "\n </label><br />";
        }
    
    function updateDiv(array){
         array.sort();
         document.getElementById('myDiv').innerHTML = astring;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main window (#1) on my webpage from which I open a
We have an advanced webpage (ASP.NET, C#), and a application which needs to be
I have a txt file which actually is a html source of some webpage.
I have a webpage that pulls information from a database, converts it to .csv
I have a webpage that has a textbox. When the user enters information into
I have an ancient webpage that I need to instill some databasing capabalities into
I have a web page which contains a select box. When I open a
I have a web page which allows the user to carry out various operations
I have built a web page which contains a Crystal Report built using the
I have a web page in which people go to register for my site.

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.