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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:05:53+00:00 2026-06-13T23:05:53+00:00

I have two selections. The second selection values depend on the first ones. When

  • 0

I have two selections. The second selection values depend on the first ones.
When the user select a value in the first select, an Action is called to fill the second select.
It works only if the user submits the form and there are validation errors.

how could I reload the div when the user selects a value in the first select?

My jquery is:

$('select[name=select1]').change(function () {
            var cod=$(this).val();
            if (cod>0) {
                $.ajax({
                    url:"Load.do",
                    data: "cod="+cod,
                    });
            }
        });

In the struts-config.xml, I have:

<action path="/Load" scope="request" type="mypackage.Load">
    <forward name="Success" path="/jsp/myForm.jsp"/>
 </action>

The class Load is an Action:

public class Load extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
{
    // TODO Auto-generated method stub

    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

    try {
        // get the connection 
        stmt = (Statement) con.createStatement();

        String cod = request.getParameter("cod");

        String select = new String("Select firstCode, name from mytable where secondCode = '");
        select = select.concat(cod);
        select = select.concat("';");
        rs = stmt.executeQuery(select);
        ArrayList<LabelValueBean> arr = new ArrayList<LabelValueBean>();            
        while (rs.next()) {
            arr.add(new LabelValueBean(rs.getString("name"),rs.getString("firstCode")));
        }

        request.getSession().setAttribute("arr", arr);

        return mapping.findForward("Success");
    } catch (NamingException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }  catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (rs != null) {
              try { rs.close(); } catch (SQLException e) {}
              rs = null;
        }
        if (stmt != null) {
              try { stmt.close(); } catch (SQLException e) {}
              stmt = null;
        }
        if (con != null) {
              try { con.close(); } catch (SQLException e) {}
              con = null;
        }        
    }

    return mapping.findForward("Failure");
}
 }

In my myForm.jsp page, the select which I want fill is:

 <html:select property="prop1">
 <html:option value="0">Choose:</html:option>
 <% if (request.getSession().getAttribute("arr") != null) { %>
<html:optionsCollection name="arr" label="label" value="value"/>
<% } %>
</html:select>
  • 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-13T23:05:54+00:00Added an answer on June 13, 2026 at 11:05 pm

    If the response data contains exactly the html you want, i.e. the correct <select> with all the options you can simply replace the 2nd select with the response data:

    $('select[name=select1]').change(function () {
        var cod=$(this).val();
        if (cod>0) {
            $.ajax({
                url:"Load.do",
                data: "cod="+cod,
                success: function(result) {
                    $('select[name=select2]').replaceWith(result); //guessing the name
                }
            });
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two dropdowns. When a user selects a value from the first one
I have two select boxes, the second of which is dependent upon the selection
I have two selection queries and i want to select values from both and
I have a form which has two inputs. The first input allows a user
I have two drop down lists. I need a selection made in the second
I have two web pages- the first is a GridView and the second is
I have two dropdowns. I want to populate the second dropdown on selection of
I have two forms here, the first is a select dropdown select, which when
I have a registration form with common registration fields and two multiple selection Lists
I have two libraries, one of which depends on the other. The first library

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.