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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:41:32+00:00 2026-05-26T03:41:32+00:00

I have a page containing two combo boxes. I want to make them in

  • 0

I have a page containing two combo boxes. I want to make them in a way that when I change the first combo box the content of the second combo box, which is got from database, is changed. How can I do it?

  • 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-26T03:41:33+00:00Added an answer on May 26, 2026 at 3:41 am

    The usual way to perform this kind of operations is through AJAX. You can easily add an AJAX Behavior to the first DropDownChoice in order to populate/refresh the choices of the second DropDownChoice.

    Let’s say you are using IModels to get the choices of both DropDownChoices. The IModel that gets the choices for the second DropDownChoice would be using the first DropDownChoice‘s ModelObject (because it is dependent).

    private DropDownChoice ddcCountry;
    private DropDownChoice ddcCity;
    //...
    
    IModel countriesModel = new LoadableDetachableModel(){
       @Override
       protected Object load() {
          return myService.getCountries();
       }
    };
    IModel citiesModel = new LoadableDetachableModel(){
       @Override
       protected Object load() {
          if (ddcCountry.getModelObject() != null){
              return myService.getCities(ddcCountry.getModelObject());
          }
          else { return new ArrayList(); }
       }
    };
    ddcCountry = new DropDownChoice("country", null, countriesModel);
    ddcCity = new DropDownChoice("city", null, citiesModel);
    

    You can attach an AjaxFormComponentUpdatingBehavior to the first DropDownChoice. That will output an onchange HTML event handler on the <select> tag, such that it will update that DropDownChoice‘s model object with the selected value, and then will call your Behavior’s onUpdate(). In the onUpdate() method, you will only have to add the second DropDownChoice to the AjaxRequestTarget to write it back through the ajax response with the updated options. Remember to use setOutputMarkupId(true) on all components you’ll be adding to the AjaxRequestTarget.

    For instance, for 2 dependent selects with countries and cities:

    ddcCity.setOutputMarkupId(true);
    ddcCountry.add(new AjaxFormComponentUpdatingBehavior(){
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            // here, ddcCountry's ModelObject has been already updated.
            ddcCity.setModelObject(null); // clear selection 
            if (target != null) { 
                // Adding the ddc to the AjaxRequestTarget will write
                // it back to the ajax response with new options pulled 
                // from the choices model.
                target.addComponent(ddcCity);
            }
        }
    }
    

    In case you’re not using IModels for your choices (i.e. using List objects in the constructors), you’d just need to get the new List in the onUpdate method, and set it to ddcCity with setChoices(). You can get the Component the Behavior is bounded to with the getComponent() method.

    protected void onUpdate(AjaxRequestTarget target) {
        // here, ddcCountry's ModelObject has been already updated.
        List cities = myService.getCities(getComponent().getModelObject());
        ddcCity.setChoices(cities);
        ddcCity.setModelObject(null); // clear selection 
        if (target != null) { 
            target.addComponent(ddcCity);
        }
    }
    

    In case you want to support users without javascript, you should add a submit button (maybe in a <noscript> tag?) with default from processing disabled, and perform that same logic in the button’s onSubmit.

    For additional reference, see this DropDownChoice Examples Wicket wiki page, you might find the “Ajax” section interesting.

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

Sidebar

Related Questions

I have a normal asp.net page containing some code that I want to measure
I have a web page containing a form that currently print comfortably in two
The Scenario Using jQuery, I have a page that has a popup overlay containing
Suppose I have two files containing styles, a.css and b.css. I import them into
I have a WebForms page that has two DropDownList controls on it that both
I am trying to make a HTML page using two column layout. I have
I have a web page containing a filtering text box and a list box.
I have a layout containing two textViews and one ImageView. the first text is
I have an asp page containing a form with two fields where the client
I have a parent page containing two iframes. One holds navigation links and the

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.