Advertisement
Guest User

Untitled

a guest
Oct 11th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.     function htmlEntities(str)
  3.     {
  4.         return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  5.     }
  6.     function showCities(city)
  7.     {
  8.         var request=new XMLHttpRequest();
  9.         request.onload=function(){
  10.             var data=JSON.parse(this.response);
  11.  
  12.             var hint="";
  13.             if(city==="")
  14.             {
  15.                 for(var i=0; i<data.length; i++)
  16.                 {
  17.                     hint+="<div class=\"cityOption\" data-city=\""+htmlEntities(data[i].שם_ישוב)+"\">"+data[i].שם_ישוב+"</div>";
  18.                 }
  19.             }
  20.             else
  21.             {
  22.                 var strlen=city.length;
  23.                 for(var i=0; i<data.length; i++)
  24.                 {
  25.                     if(city.localeCompare((data[i].שם_ישוב).substr(0, strlen))==0)
  26.                     {
  27.                         hint+="<div class=\"cityOption\" data-city=\""+htmlEntities(data[i].שם_ישוב)+"\"><strong>"+(data[i].שם_ישוב).substr(0, strlen)+"</strong>"+(data[i].שם_ישוב).substr(strlen)+"</div>";
  28.                     }
  29.                 }
  30.             }
  31.             if(hint==="")
  32.             {
  33.                 hint+="אין הצעות";
  34.             }
  35.             $("#citiesSuggestions").html(hint);
  36.             $(".cityOption").mousedown(function(){
  37.                 var selectedCity=$(this).data("city");
  38.                 $("#City").val(selectedCity);
  39.                 $("#Street").prop("disabled", false);
  40.                 showStreets(selectedCity);
  41.             });
  42.         }
  43.         request.open("GET", "yeshuvim.json", true);
  44.         request.send();
  45.     }
  46.     function showStreets(city, street)
  47.     {
  48.         var request=new XMLHttpRequest();
  49.         request.onload=function(){
  50.             var data=JSON.parse(this.response);
  51.  
  52.             var hint="";
  53.             if(street==undefined)
  54.             {
  55.                 for(var i=0; i<data.length; i++)
  56.                 {
  57.                     if((data[i].שם_ישוב).localeCompare(city)==0)
  58.                     {
  59.                         hint+="<div class=\"streetOption\" data-street=\""+htmlEntities(data[i].שם_רחוב)+"\">"+htmlEntities(data[i].שם_רחוב)+"</div>";
  60.                     }
  61.                 }
  62.             }
  63.             else
  64.             {
  65.                 var strlen=street.length;
  66.                 for(var i=0; i<data.length; i++)
  67.                 {
  68.                     if((data[i].שם_ישוב).localeCompare(city)==0)
  69.                     {
  70.                         if(street.localeCompare((data[i].שם_רחוב).substr(0, strlen))==0)
  71.                         {
  72.                             hint+="<div class=\"streetOption\" data-street=\""+htmlEntities(data[i].שם_רחוב)+"\"><strong>"+(data[i].שם_רחוב).substr(0, strlen)+"</strong>"+(data[i].שם_רחוב).substr(strlen)+"</div>";
  73.                         }
  74.                     }
  75.                 }
  76.             }
  77.             $("#Street").focus();
  78.             $("#streetsSuggestions").html(hint);
  79.             $("#streetsSuggestions").show();
  80.             $(".streetOption").mousedown(function(){
  81.                 $("#Street").val($(this).data("street"));
  82.             });
  83.             $("#Street").on({
  84.                 blur: function(){
  85.                     $("#streetsSuggestions").hide();
  86.                 },
  87.                 focus: function(){
  88.                     showStreets(city, $(this).val());
  89.                 },
  90.                 keyup: function(){
  91.                     showStreets(city, $(this).val());
  92.                 }
  93.             });
  94.         }
  95.         request.open("GET", "rechovot.json", true);
  96.         request.send();
  97.     }
  98.  
  99.     $(document).ready(function(){
  100.         $("#City").on({
  101.             focus: function(){
  102.                 showCities($(this).val());
  103.                 $("#citiesSuggestions").show();
  104.             },
  105.             keyup: function(){
  106.                 showCities($(this).val());
  107.             },
  108.             blur: function(){
  109.                 $("#citiesSuggestions").hide();
  110.             }
  111.         });
  112.     });
  113. </script>
  114. <div id="newclient">
  115.     <form action="" method="post">
  116.         <fieldset>
  117.             <div id="row">
  118.                 <label for="City">עיר:</label>
  119.                 <input type="text" name="City" id="City" placeholder="הכנס עיר" class="value" autocomplete="off" />
  120.                 <div id="citiesSuggestions"></div>
  121.             </div>
  122.  
  123.             <div id="row">
  124.                 <label for="Street">רחוב:</label>
  125.                 <input type="text" name="Street" id="Street" placeholder="הכנס רחוב" class="value" autocomplete="off" disabled="disabled" />
  126.                 <div id="streetsSuggestions"></div>
  127.             </div>
  128.         </fieldset>
  129.     </form>
  130. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement