Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('#edit-shift').cascadingDropdown({
- selectBoxes: [
- {
- selector: '.clients',
- source: function(request, response) {
- $.getJSON('returnClientList.php', request, function(data) {
- var selectOnlyOption = data.length <= 1;
- response($.map(data, function(item, index) {
- return {
- label: item.label,
- value: item.value,
- selected: selectOnlyOption // Select if only option
- };
- }));
- });
- }
- },
- {
- selector: '.sites',
- requires: ['.clients'],
- source: function(request, response) {
- $.getJSON('returnSiteList.php', request, function(data) {
- var selectOnlyOption = data.length <= 1;
- response($.map(data, function(item, index) {
- return {
- label: item.label,
- value: item.value,
- selected: selectOnlyOption // Select if only option
- };
- }));
- });
- }
- },
- {
- onChange: function(event, value, requiredValues){}
- }
- ]
- });
- //this script returns a json array for use in jquery autocomplete fields for site lists...
- header('Content-type: application/json');
- require("connect.php");
- $client_id = $_GET['?'];
- //do the query for sites that are active
- $sql = "SELECT * FROM site WHERE active=1 AND client_id='$client_id' ORDER BY site_name ASC";
- $result = mysql_query($sql) or die('Error: ' . mysql_error());
- //loop the results and create php array
- while($row = mysql_fetch_array($result)){
- $arr[] = array('label' => $row['site_name'], 'value' => $row['id']);
- }
- echo json_encode($arr);
- //dynamically returns the sites once the user chooses a client - edit/add shift form
- $('.client-id').change(function () {
- var selectedClient = $(this).val();
- if (selectedClient != null && selectedClient != '') {
- $.getJSON('returnSiteList.php', { id: selectedClient },
- function (Sites) {
- var siteSelect = $('.site-id');
- siteSelect.empty();
- $.each(Sites, function (index, site) {
- siteSelect.append($('<option/>', {
- value: site.value,
- text: site.label
- }));
- });
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement