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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:00:34+00:00 2026-06-11T13:00:34+00:00

I am using JQuery to insert HTML in my DIV element I have the

  • 0

I am using JQuery to insert HTML in my DIV element
I have the following code in my JSP page

<div id="definitionsDiv">
    <s:select id="typeDropdown" list="types" listKey="id" listValue="value" value="3" onchange="getWordList()"/>        
</div>

HTML looks like

<div id="definitionsDiv">
  <select id="typeDropdown" onchange="getWordList()" name="">
    <option value="1">Adverb</option>
    <option value="2">Adjective</option>
    <option selected="selected" value="3">Noun</option>
    <option value="4">Other</option>
  </select>
</div>

This works fine and displays a dropdown with the values retrieved from the “types” field in my Struts action.
However, I want to dynamically generate this HTML so I call the following in my doc load method ….

function buildDefinitionsHTML()
{
    $("#definitionsDiv").empty();
    $("#definitionsDiv").append('<s:select id="typeDropdown" list="types" listKey="id"     listValue="value" value="1" onchange="getWordList()"/>');
}

Now my generated HTML looks like

<div id="definitionsDiv">
  <s:select id="typeDropdown" onchange="getWordList()" value="1" listvalue="value"     listkey="id" list="types"></s:select>
</div>

It seems there has been no call made back to my action to populate the options list as happens when I leave the static HTML in my page. Any ideas how to get this to work?

  • 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-06-11T13:00:36+00:00Added an answer on June 11, 2026 at 1:00 pm

    It’s impossible for client-side JavaScript to add server-side code to a page. What you need to do is create both blocks of HTML server-side and hide one of them.

    JSP isn’t my area, but this might work. JSP/HTML:

    <div id="definitionsDiv">
        <s:select id="typeDropdown" list="types" listKey="id" listValue="value" value="3" onchange="getWordList()"/>        
    </div>
    <div id="definitionsDiv2" style="display:none">
      <s:select id="typeDropdown" onchange="getWordList()" value="1" listvalue="value"     listkey="id" list="types"></s:select>
    </div>
    

    jQuery:

    function buildDefinitionsHTML() {
        $("#definitionsDiv").empty().append($('#definitionsDiv2').children()); 
    }
    

    Using .append() in this way will move the existing DOM elements from the hidden DIV into the desired target DIV.

    However, using display:none only hides the second DIV from the page; it doesn’t remove it. Therefore, you may want to move definitionsDiv2 outside of your <form> tags so it doesn’t get submitted invisibly along with definitionsDiv.

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

Sidebar

Related Questions

How would I insert a container div using jQuery? From <div id=page> <!-- a
When using jQuery to insert HTML into a div in IE8, IE8 strips the
How can I insert jquery inside an html tag like using it in onclick
I am trying to insert a div inside another div using add() of jquery
I am new to jquery ! I am using the code below to insert
Using jQuery Nearest Element , I would like to select elements in a circular
I'm using some embed codes that insert HTML to the page dynamically and since
How do I dynamically insert an iframe in a div using jQuery? $(document).ready(function() {
I'm loading and inserting html-code using Jquery Load() method. But when I'm trying to
How to insert <div> within a <td> using JQuery and place all the child

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.