home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (uc_country_select.js)

This example Drupal source code file (uc_country_select.js) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

100, background-image, background-position, background-repeat, contents, country_id, else, function, nbsp, options, php, url, var, zone_select

The uc_country_select.js Drupal example source code

// $Id: uc_country_select.js,v 1.6.2.3 2009/08/17 21:27:54 islandusurper Exp $

/**
 * @file
 * Switches the zones list when a country is chosen for an address.
 */

/**
 * Set the select box change behavior for the country selector
 */
Drupal.behaviors.ucCountrySelect = function(context) {
  $('select[id$=-country]:not(.ucCountrySelect-processed)', context).addClass('ucCountrySelect-processed').change(
    function() {
      uc_update_zone_select(this.id, '');
    }
  );
}

/**
 * Update the zone select element with new options.
 */
function uc_update_zone_select(country_select, default_zone) {
  var zone_select = country_select.substr(0, country_select.length - 8) + '-zone';

  var options = { 'country_id' : $('#' + country_select).val() };

  $('#' + zone_select).parent().siblings('.zone-throbber').attr('style', 'background-image: url(' + Drupal.settings.basePath + 'misc/throbber.gif); background-repeat: no-repeat; background-position: 100% -20px;').html('    ');

  $.post(Drupal.settings.basePath + '?q=uc_js_util/zone_select', options,
         function (contents) {
           if (contents.match('value="-1"') != null) {
             $('#' + zone_select).attr('disabled', 'disabled');
           }
           else {
             $('#' + zone_select).removeAttr('disabled');
           }
           $('#' + zone_select).empty().append(contents).val(default_zone).change();
           $('#' + zone_select).parent().siblings('.zone-throbber').removeAttr('style').empty();
         }
  );
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal uc_country_select.js source code file:

new blog posts

 


"Drupal" is a registered trademark of Dries Buytaert.

our drupal tutorials and examples  
 

Copyright 1998-2014 Alvin Alexander, alvinalexander.com
All Rights Reserved.