• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Sorting array in bind("change", function()  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am using .bind("change", function() on a select dropdownlist,where it will load the departments of the praticular selected instituion.
There is Map<String,String> in categorySelect.
I want the list to be in sorted order when I change the value for institution.
Ho I can do this.Below is my code in jsp.

<script>
jQuery(document).ready(function() {
//alert("first");
$('#tblDeptMapping').hide();
$("#institution").bind("change", function() {
// alert($(this).val());
GetSubCategories($(this).val());
// fetchJSONData();
});
}
);
function GetSubCategories(category) {
$("#department").get(0).options.length=0;
$("#department").get(0).options[0]= new Option("--- Please Select ---","Please Select");
mapLen = $("#categorySelect").get(0).options.length;
// alert(mapLen);
for(var x=0; x < mapLen; x++){
if( ($("#categorySelect").get(0).options[x].value).match(category)){
$("#department").get(0).options[$("#department").get(0).options.length] = new Option( $("#categorySelect").get(0).options[x].text);
}
}
}
<script>

<s:select label="Select an Institution" name="institution" id="institution" headerKey="1" headerValue="--- Please Select ---"
list="instList"/>

<s:select label="Select a Department" name="department" id="department" headerKey="1" headerValue="--- Please Select ---" list="deptList"/>


<input type="hidden" name="filePath" id="filePath"/>

<table id="tblDeptMapping">
<s:select name="categorySelect" id="categorySelect" list="deptMap"/>
</table>
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!