Is there any way to write more generic code in below code?
Hello All,
I recently started coding. Please help me to write more generic way of writing below code.
- function set_selection(elem)
- {
- switch(elem.id){
- case "div_SortCost" :
- if(elem.id == "div_SortCost")
- {
- if(btnSortNumber.elem !=null)
- {
- btnSortNumber.disactivateSelection();
- }
- if(btnSortCost.elem!=null)
- {
- btnSortCost.activateSelection();
- }
- if(btnSortHour.elem!=null)
- {
- btnSortHour.disactivateSelection();
- }
- }
- break;
-
- case "div_SortHour":
- if(btnSortNumber.elem!=null)
- {
- btnSortNumber.disactivateSelection();
- }
- if(btnSortCost.elem!=null)
- {
- btnSortCost.disactivateSelection();
- }
- if(btnSortHour.elem!=null)
- {
- btnSortHour.activateSelection();
- }
- break;
-
- case "div_SortNumber":
- if(btnSortNumber.elem!=null)
- {
- btnSortNumber.activateSelection();
- }
- if(btnSortHour.elem!=null)
- {
- btnSortHour.disactivateSelection();
- }
- if(btnSortCost.elem!=null)
- {
- btnSortCost.disactivateSelection();
- }
- break;
- }
- }
Thanks
Chandu