Guest User

Untitled

a guest
Jul 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. (function($){
  2. $.fn.zipcodeLookup = function(options) {
  3. var options = $.extend($.fn.zipcodeLookup.defaults, options);
  4.  
  5. return this.each(function() {
  6. $this = $(this);
  7. zipInput = $('.'+options.zipInput)[0];
  8. zipInput.keyup(function(){
  9. if((zipInput.value != '' || zipInput.value != null) && zipInput.value.length == 5 {
  10. try {
  11. var path = options.yahooAPIBase+options.yahooAPIAppId+'&zip='+zipInput.value;
  12. $.ajax({
  13. type: 'GET',
  14. url: options.proxyURL+'?yws_path='+encodeURIComponent(path),
  15. success: function(data){
  16. $('Result',data).each(function(i){
  17. zip = data.find('Zip').text();
  18. if(zip == null || zip == ''){
  19. alert('Please check your zip code.');
  20. exit();
  21. } else {
  22. if(stateValue = $('.'+options.stateInput)[0]) stateValue.value = data.find('State').text();
  23. if(cityValue = $('.'+options.cityInput)[0]) cityValue.value = data.find('City').text();
  24. }
  25. });
  26. },
  27. dataType: 'xml'
  28. });
  29. } catch(e) {}
  30. }
  31. }).change();
  32. });
  33. };
  34. $.fn.zipcodeLookup.defaults = {
  35. zipInput: 'zipInput',
  36. stateInput: 'cityInput',
  37. cityInput: 'stateInput',
  38. yahooAPIBase: 'MapsService/V1/geocode?appid=',
  39. yahooAPIAppId: '',
  40. proxyURL: 'request.php',
  41. zipError: 'Please check your zip code.'
  42. };
  43. })(jQuery);
  44.  
  45.  
  46.  
  47. // call to this plugin using:
  48.  
  49. $(document).ready(function() {
  50. $('#testForm').zipcodeLookup({
  51. yahooAPIAppId:'0Ro_9_vV34H4Kqvj3XPt3IABw4PnzKJWMAEkL2nwe2WsBPbyvxBCVnzC0k0na7Pd'
  52. });
  53. });
Add Comment
Please, Sign In to add comment