Search code examples
freemarkerspring-form

Change freemarker Single Select macro by jquery


I am using <@spring.formSingleSelect "PersonalInfoBean.district" distMap! ""/> freemarker macro to display a select option in ftl page. where distMap is a HashMap<String, String>contains the districts as key(distId), value(distName). And its work fine.

Now I want to change the options/distMap dynamically(from another select onchange) using javascript like ajax and fetching data from server-side. I am using SpringMVC. I am able to fetch String or json data from server by ajax call. But can't replace that distMap/options.


Solution

  • I got my problem after a day. I used chosen-select in <select class="chosen-select"> DOM.

    I change the update script by....

    $(target).empty().append(options).trigger("chosen:updated");
    

    and it works.