Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($){
- $.fn.zipcodeLookup = function(options) {
- var options = $.extend($.fn.zipcodeLookup.defaults, options);
- return this.each(function() {
- $this = $(this);
- zipInput = $('.'+options.zipInput)[0];
- zipInput.keyup(function(){
- if((zipInput.value != '' || zipInput.value != null) && zipInput.value.length == 5 {
- try {
- var path = options.yahooAPIBase+options.yahooAPIAppId+'&zip='+zipInput.value;
- $.ajax({
- type: 'GET',
- url: options.proxyURL+'?yws_path='+encodeURIComponent(path),
- success: function(data){
- $('Result',data).each(function(i){
- zip = data.find('Zip').text();
- if(zip == null || zip == ''){
- alert('Please check your zip code.');
- exit();
- } else {
- if(stateValue = $('.'+options.stateInput)[0]) stateValue.value = data.find('State').text();
- if(cityValue = $('.'+options.cityInput)[0]) cityValue.value = data.find('City').text();
- }
- });
- },
- dataType: 'xml'
- });
- } catch(e) {}
- }
- }).change();
- });
- };
- $.fn.zipcodeLookup.defaults = {
- zipInput: 'zipInput',
- stateInput: 'cityInput',
- cityInput: 'stateInput',
- yahooAPIBase: 'MapsService/V1/geocode?appid=',
- yahooAPIAppId: '',
- proxyURL: 'request.php',
- zipError: 'Please check your zip code.'
- };
- })(jQuery);
- // call to this plugin using:
- $(document).ready(function() {
- $('#testForm').zipcodeLookup({
- yahooAPIAppId:'0Ro_9_vV34H4Kqvj3XPt3IABw4PnzKJWMAEkL2nwe2WsBPbyvxBCVnzC0k0na7Pd'
- });
- });
Add Comment
Please, Sign In to add comment