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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:46:32+00:00 2026-05-24T20:46:32+00:00

I would still need some help with my dynamic selectlist. I have the sript:

  • 0

I would still need some help with my dynamic selectlist.

I have the sript:

function getMains(element) {
var subjectgroup = element.value;

  var select_element;

  select_element = '#mains';


$(select_element).html('');
$(select_element).append($("<option></option>").attr("value","none").html(""));
 //   $(select_element).append($("<option></option>").attr("value","all").html(""));
   if (element.value==''||element.value=='none'||element.value=='all')
  return;
 $.ajax({
  type: 'GET',
  url: 'getmainsubjects.html',
  dataType: 'json',
  data: ({id:data}),
  success: function(data) {
    $.each(function(data) {
      if (!subjectgroup) {
                                                                                                                                      $(select_element).append($("                                                                  <option>").attr("value",data.id,"items",data).html(data.description));
   } else {
    $(select_element).append($("<option>").attr("value",data.id,"items",data).html(data.description));
}

    });
  },
  error: function(data) {
    //alert("This failed!");
       }
     });

   }  

 $('select#subjectgroups').ready(function(){
  $("select#subjectgroups").find("option").each(function(i) {
  if ($(this).val()!='all'&&$(this).val()!='none') {
    $(this).append( " " + $(this).val() );
  }
});

});

   $('select#mains').ready(function(){
  $("select#mains").find("option").each(function(i) {
    if ($(this).val()!='all'&&$(this).val()!='none') {
     $(this).append( " " + $(this).val() );
    }
 });
});

And the method:

@RequestMapping(method = RequestMethod.GET, params="id", value = "/getmainsubjects")
     @ResponseBody
   public String getMainSubjects( @RequestParam("id") int id) {


    List<MainSubjectsSimple> mains = database.getMainSubjectsSimple(id,   Localization.getLanguage());
    //System.out.println(mains.size());
    HashMap hm = new HashMap();



     for (MainSubjectsSimple mss: mains) {
        try {

            hm.put("id",mss.getId());
            hm.put("description", mss.getDescription());

        } catch (NoSuchMessageException e) {
            //hm.add(Integer.valueOf(mss.getId().toString(), translate(mss.getTranslationCode(),new Locale("fi")));
        }
    }
    String json = null;
    String _json = null;

    try {
        _json = HtmlEntityEncoder.encode(JsonUtils.javaToStr(hm));

    } catch (Exception e) {

    }
    return _json;
}

I think I’m not looping the right values. Mains selectlist should be populated based on other selectlist so that the object’s id is the value and description the label. Right now calling the url written in script returns only first object as json, not all of them, and the objects are not shown in mains selectlist.

  • 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-24T20:46:32+00:00Added an answer on May 24, 2026 at 8:46 pm

    You are putting the same keys over and over again to the Map hm:

    HashMap hm = new HashMap();

     for (MainSubjectsSimple mss: mains) {
        try {
    
            hm.put("id",mss.getId());
            hm.put("description", mss.getDescription());
    
        } catch (NoSuchMessageException e) {
            //hm.add(Integer.valueOf(mss.getId().toString(),
    

    translate(mss.getTranslationCode(),new Locale(“fi”)));
    }
    }

    You need to use different keys for each entry in mains or use a collection (e.g. ArrayList) of Maps. An example of the latter:

    List hms = new ArrayList();
    
         for (MainSubjectsSimple mss: mains) {
            try {
                HashMap hm = new HashMap();
    
                hm.put("id",mss.getId());
                hm.put("description", mss.getDescription());
    
                hms.add(hm);
    
            } catch (NoSuchMessageException e) {
                //hm.add(Integer.valueOf(mss.getId().toString(), translate(mss.getTranslationCode(),new Locale("fi")));
            }
        }
    
        ...
    
        try {
            _json = HtmlEntityEncoder.encode(JsonUtils.javaToStr(hms));
    
        } catch (Exception e) {
    
        }
    

    I’m not familiar with the utils (JsonUtils) you are using so this might not work directly but the principle is the same anyways.

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

Sidebar

Related Questions

I'm pretty new to arrays still. I need some help - I have some
still new to the world of linq, and i need some help flatening a
I know I'm breaking some rules here with dynamic SQL but I still need
I have a form field in Drupal which I need some help with. The
I have a SQL question that I could use some help with. Still somewhat
I'm still pretty new to perl and regex and need some help getting started.
I have to convert values (double/float in C#) to bytes and need some help..
I was wondering would I still need to use a basic game loop for
Assuming you had some kind of factory-created resource that would still belong to the
Still an iphone dev starter but trying. I would like to have the user

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.