title: how to insert/pass an result value city into input field value=“city”
body: <p>This script works well, the town that it generates function must register in  but he generates so  city </p>
  
  <p>how to insert/pass value <code>#city</code> into input field</p>
  
  <blockquote>
    <p>value="cityname"</p>
  </blockquote>
  
  <pre><code>&lt;input id="city" name="input" value="cityname" /&gt;
  
  &lt;script&gt;
  $(document).ready( function () {    
      var lat = 37.42;
      var long = -122.08;
  
      $.ajax({
          type: 'GET',
          dataType: "json",
          url: "http://maps.googleapis.com/maps/api/geocode/json?latlng="+lat+","+long+"&amp;sensor=false",
          data: {},
          success: function(data) {
              $('#city').html(data);
              $.each( data['results'],function(i, val) {
                  $.each( val['address_components'],function(i, val) {
                      if (val['types'] == "locality,political") {
                          if (val['long_name']!="") {
                              $('#city').html(val['long_name']);
                          }
                          else {
                              $('#city').html("unknown");
                          }
                          console.log(i+", " + val['long_name']);
                          console.log(i+", " + val['types']);
                      }
                  });
              });
              console.log('Success');
          },
          error: function () { console.log('error'); } 
      }); 
  });
  &lt;/script&gt;
  </code></pre>