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 6543155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:18:45+00:00 2026-05-25T11:18:45+00:00

I am generating dynamically some selects in a jsp page with javascript. The code

  • 0

I am generating dynamically some selects in a jsp page with javascript. The code works fine. But I having an issue, and don’t know how to deal with it. Well, this is the javascript code:

 $('#addRow').click(function(){

        i++;

        //stuff categories
        var categoriesStr = '${stuffCategoriesListStr}';
        categoriesStr = categoriesStr.replace('[', '');
        categoriesStr = categoriesStr.replace(']', '');
        var categoriesList = categoriesStr.split(', ');

        var selectCategoriesHtml = "<select id='category"+i+"' style='width: 200px;' onchange=\"retrieveUrlAjax('ajaxstuff.action?category='+this.value, 'menusCombobox"+i+"')\"><option value='-1'>-- Select category --</option>";

        for (j = 0; j < categoriesList.length; j++) {

            var option = "<option value='"+categoriesList[j]+"'>"+categoriesList[j]+"</option>";
            selectCategoriesHtml += option;
        }

        selectCategoriesHtml += "</select>";
        //end os stuff categories

        //units list
        var unitsStr = '${unitsListStr}';
        unitsStr = unitsStr.replace('[','');
        unitsStr = unitsStr.replace(']','');
        var unitsList = unitsStr.split(', ');            

        var selectUnitsHtml = "<select id='unit+"+i+"' style='width: 200px;'><option value='-1'>-- Select unit --</option>";

        for (j = 0; j < unitsList.length; j++) {

            var option = "<option value='"+unitsList[j]+"'>"+unitsList[j]+"</option>";
            selectUnitsHtml += option;
        }

        selectUnitsHtml += "</select>";
        //end of units list

        var d = document.getElementById("fields");
        d.innerHTML += "<table width='100px'>\n\
                            <tr>\n\
                                <td>"+selectCategoriesHtml+"</td>\n\
                                <td width='100px;'><div class='menusCombobox"+i+"'><select style='width: 200px;'/></div></td>\n\
                                <td width='1%'><input type='text' style='width: 40px;' id='"+i+"' value='1'/></td>\n\
                                <td width='200px'>"+selectUnitsHtml+"</td>\n\
                            </tr>\n\
                        </table>";
    });        

And here it is the div:

 <div id="fields"></div>

And the result:

1 screen: http://img199.imageshack.us/img199/4662/screenshot1hrpl.png

2 screen: http://img827.imageshack.us/img827/5717/screenshot2hn.png

The problem is that when I am choosing something in first row, and then add another row, then all the data from the first row that was chosen is reseted. You can see this in the first and second screens. I think the problem is in the innerHTML, but I haven’t found other alternatives. Maybe you guys can help me.

  • 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-25T11:18:46+00:00Added an answer on May 25, 2026 at 11:18 am

    I think it is the innerHTML that’s causing you the problem, have a look at this question –

    Is it possible to append to innerHTML without destroying descendants' event listeners?

    As you’re using jQuery could you use something like append or after instead?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems really simple, but for some reason Im stumped.. Im dynamically generating an
I am dynamically generating some c# code using the CodeDom. I want to ad
Thanks for reading this. I am dynamically generating some data which includes a select
I'm generating some opcodes dynamically in a JIT compiler and I'm looking for guidelines
What are some pros/cons for using the Reflection.Emit library versus CodeDOM for dynamically generating
i'm generating controls dynamically on my asp.net page by xslt transformation from an xml
i am having a application where i am generating the uibuttons dynamically want to
I'm dynamically generating some charts using mod_python, in .png and .pdf formats. When a
I've ran into one small problem. I am dynamically generating some controls and place
I'm generating PDFs dynamically using PHP and PDFlib and some of the fields require

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.