Note that there are some explanatory texts on larger screens.

plurals
  1. POCombobox Value Disappears After Select
    text
    copied!<p>There are two comboboxes on my JSP page.The values of them are coming from a JSON page. When you select a value from the first combobox, then second combobox values are listed according to first combobox's id. The first combobox is for country name, the second is for city names.</p> <pre><code>&lt;select onchange="ListCities()" id="ListCountries"&gt; &lt;% String CountryId,CountryName; for(int k=0;k&lt;= jsonarray.length()-1;k++ ) { CountryId = jsonarray.getJSONObject(k).get("id").toString(); CountryName = jsonarray.getJSONObject(k).get("name").toString(); out.print("&lt;option value=" + CountryId +"&gt;" +CountryName+ "&lt;/option&gt;"); } %&gt; &lt;/select&gt; &lt;select id="ListCities"&gt; &lt;% String CityId,CityName; for(int k=0;k&lt;= jsonIlArray.length()-1;k++ ) { CityId= jsonCityArray.getJSONObject(k).get("id").toString(); CityName= jsonCityArray.getJSONObject(k).get("name").toString(); out.print("&lt;option value=" + CityId+"&gt;" +CityName+ "&lt;/option&gt;"); } %&gt; </code></pre> <h2> </h2> <pre><code>function ListCities() { var CountryIdFromCB = document.getElementById("CountryList").value; document.location.href = ('?CountryId='+ CountryIdFromCB); } </code></pre> <p>The values of comboboxes are working properly. When you select any item from the first combobox(the second box are listed according to the first combobox's id), the JSP page passes the first combobox's id as parameter to the second combobox. BUT, the selected combobox item is disappeared when the page is refreshed. I would like to keep the first combobox's value even the user selects any item from second combobox.</p> <p>I don't want to use JQuery, I am looking for pure Javascript solutions.</p> <p>Thanks,Mark</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload