Advertisement
Guest User

Untitled

a guest
May 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // My version
  3. $(document).ready(function(){
  4.    
  5.     $("#itemBox").css("display","none");
  6.  
  7.  
  8.     $(".itemList").click(function(){
  9.        
  10.        
  11.         if( $('input[name=selection]:checked') ){
  12.            
  13.             var radioValue = $('input[name=selection]:checked').val();
  14.            
  15.             $("#itemBox").slideDown("fast"); // Slide down effect
  16.             $.cookie('showTop', 'expanded'); // Add cookie for showtop
  17.            
  18.            
  19.             if( radioValue == "Department" ){
  20.                 params = "action=getElementList&type=department";
  21.                 populateDropdown( params, "Department: " );
  22.            
  23.             }else if( radioValue == "Building" ){
  24.            
  25.                 params = "action=getElementList&type=building";
  26.                 populateDropdown( params, "Buildings" );
  27.            
  28.             }else if( radioValue == "Location" ){
  29.            
  30.                 params = "action=getElementList&type=location";
  31.                 populateDropdown( params, "Locations: " );
  32.            
  33.             }else if( radioValue == "Route" ){
  34.                
  35.                 params = "action=getElementList&type=route";
  36.                 populateDropdown( params, "Routes: " );
  37.            
  38.            
  39.            
  40.             }else{
  41.                 $("itemBox").slideUp("fast");
  42.                 $.cookie('showTop', 'collapsed');
  43.             }
  44.         }
  45.        
  46.     }); // End click
  47.    
  48.     function populateDropdown( params, labelDesc ){
  49.        
  50.         $.ajax({
  51.                type: "POST",
  52.             url: "formController.php",
  53.             data: params,
  54.             dataType: 'json',
  55.             timeout:100000,
  56.             success: function (result) {
  57.                 //alert( "my results: "+result );
  58.                 //$("#departmentList").empty().append(result);
  59.                 //$("#departmentList").html( result )
  60.                 $('#department label').text( labelDesc );
  61.                
  62.                 $('#itemList').empty(); // clears the existing items out of the drop down
  63.                 $.each(result, function(val, text) {
  64.                     $('#itemList').append(
  65.                         $('<option></option>').val(val).html(text)
  66.                     );
  67.                 });
  68.  
  69.             }
  70.         });
  71.     }
  72. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement