Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. $('#edit-shift').cascadingDropdown({
  2. selectBoxes: [
  3. {
  4. selector: '.clients',
  5. source: function(request, response) {
  6. $.getJSON('returnClientList.php', request, function(data) {
  7. var selectOnlyOption = data.length <= 1;
  8. response($.map(data, function(item, index) {
  9. return {
  10. label: item.label,
  11. value: item.value,
  12. selected: selectOnlyOption // Select if only option
  13. };
  14. }));
  15. });
  16. }
  17. },
  18. {
  19. selector: '.sites',
  20. requires: ['.clients'],
  21. source: function(request, response) {
  22. $.getJSON('returnSiteList.php', request, function(data) {
  23. var selectOnlyOption = data.length <= 1;
  24. response($.map(data, function(item, index) {
  25. return {
  26. label: item.label,
  27. value: item.value,
  28. selected: selectOnlyOption // Select if only option
  29. };
  30. }));
  31. });
  32.  
  33. }
  34. },
  35. {
  36. onChange: function(event, value, requiredValues){}
  37. }
  38. ]
  39. });
  40.  
  41. //this script returns a json array for use in jquery autocomplete fields for site lists...
  42. header('Content-type: application/json');
  43. require("connect.php");
  44.  
  45. $client_id = $_GET['?'];
  46.  
  47. //do the query for sites that are active
  48. $sql = "SELECT * FROM site WHERE active=1 AND client_id='$client_id' ORDER BY site_name ASC";
  49. $result = mysql_query($sql) or die('Error: ' . mysql_error());
  50.  
  51. //loop the results and create php array
  52. while($row = mysql_fetch_array($result)){
  53. $arr[] = array('label' => $row['site_name'], 'value' => $row['id']);
  54. }
  55.  
  56. echo json_encode($arr);
  57.  
  58. //dynamically returns the sites once the user chooses a client - edit/add shift form
  59. $('.client-id').change(function () {
  60. var selectedClient = $(this).val();
  61. if (selectedClient != null && selectedClient != '') {
  62.  
  63. $.getJSON('returnSiteList.php', { id: selectedClient },
  64. function (Sites) {
  65. var siteSelect = $('.site-id');
  66. siteSelect.empty();
  67. $.each(Sites, function (index, site) {
  68. siteSelect.append($('<option/>', {
  69. value: site.value,
  70. text: site.label
  71. }));
  72. });
  73. });
  74. }
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement