Advertisement
WarGot

Untitled

Sep 17th, 2014
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.19 KB | None | 0 0
  1. <script>
  2. function control(){
  3.     var $building = $('#gcs_guest_registration_buildingId');
  4.     var $floor = $('#gcs_guest_registration_floorId');
  5.     // When sport gets selected ...
  6.     $('form select').on('change', function(){
  7.       // ... retrieve the corresponding form.
  8.       var $form = $(this).closest('form');
  9.       // Simulate form data, but only include the selected sport value.
  10.       var data = {};
  11.       data[$building.attr('name')] = $building.val();
  12.       data[$floor.attr('name')] = $floor.val();
  13.       //data[$building.attr('name')] = $building.val();
  14.       data['_csrf_token'] = $('#gcs_guest_registration__token').val();  
  15.  
  16.       // Submit data via AJAX to the form's action path.
  17.       $.ajax({
  18.         url : $form.attr('action'),
  19.         type: $form.attr('method'),
  20.         data : data,
  21.         success: function(html) {
  22.             $form.html($(html).find('form'));
  23.             control();
  24.           // Replace current position field ...
  25.           //$('#gcs_guest_registration_floorId').replaceWith(
  26.             // ... with the returned one from the AJAX response.
  27.             //$(html).find('#gcs_guest_registration_floorId')
  28.          
  29.           // Position field now displays the appropriate positions.
  30.         }
  31.       });
  32.     });
  33. }
  34. control();
  35. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement