I am struggling making this form dynamic. I have a loop that allows the customer to choose 1 thru 5 when the user chooses it does that number of loops. I am trying to figure out where I need to add `_<cfoutput>#Add#</cfoutput>` so that when it loops it just adds a number and still works properly. The loop is working, the form is working when "1 Loop" is chosen. I am just not sure where to add `_<cfoutput>#Add#</cfoutput>` in the JavaScript to make the second loop works correctly as well so that it receives a new name and id. Everything I have tried has just been breaking the JavaScript. Suggestions and advice would be greatly appreciated!

**Appearance of the loop**  

<http://jsfiddle.net/bobrierton/gettgpmj/5/> (Not Looping the JavaScript for geolocation)

![enter image description here](https://i.stack.imgur.com/hMIul.png)

```js
var placeSearch, autocomplete, autocomplete2;
var componentForm = {
  route: 'long_name',
  locality: 'long_name',
  administrative_area_level_1: 'short_name',
  postal_code: 'short_name'
};
var componentForm2 = {
  route2: 'long_name',
  locality2: 'long_name',
  administrative_area_level_12: 'short_name',
  postal_code2: 'short_name'
};

function initialize() {
  // Create the autocomplete object, restricting the search
  // to geographical location types.
  autocomplete = new google.maps.places.Autocomplete(
    /** @type {HTMLInputElement} */
    (document.getElementById('autocomplete')), {
      types: ['geocode']
    });
  autocomplete2 = new google.maps.places.Autocomplete(
    /** @type {HTMLInputElement} */
    (document.getElementById('autocomplete2')), {
      types: ['geocode']
    });
  // When the user selects an address from the dropdown,
  // populate the address fields in the form.
  google.maps.event.addListener(autocomplete, 'place_changed', function() {
    fillInAddress();
  });
  google.maps.event.addListener(autocomplete2, 'place_changed', function() {
    fillInAddress2();
  });
}

// [START region_fillform]
function fillInAddress() {
  // Get the place details from the autocomplete object.
  var place = autocomplete.getPlace();

  for (var component in componentForm) {
    document.getElementById(component).value = '';
    document.getElementById(component).disabled = false;
  }

  // Get each component of the address from the place details
  // and fill the corresponding field on the form.
  for (var i = 0; i < place.address_components.length; i++) {
    var addressType = place.address_components[i].types[0];
    if (componentForm[addressType]) {
      var val = place.address_components[i][componentForm[addressType]];
      document.getElementById(addressType).value = val;
    }
  }
  //var keys=[];for (var key in place.address_components[0]) keys.push(key);
  //alert(keys):
  document.getElementById('autocomplete').value = 
    place.address_components[0]['long_name'] + ' ' +
    place.address_components[1]['long_name'];

  /*document.getElementById('route').value = (document.getElementById('chbSame').checked ? document.getElementById('autocomplete').value : '');*/
  document.getElementById('route').value = '';
}

function fillInAddress2() {
    // Get the place details from the autocomplete object.
    var place = autocomplete2.getPlace();

    for (var component in componentForm2) {

      document.getElementById(component).value = '';
      document.getElementById(component).disabled = false;
    }

    // Get each component of the address from the place details
    // and fill the corresponding field on the form.
    for (var i = 0; i < place.address_components.length; i++) {
      var addressType = place.address_components[i].types[0];
      if (componentForm2[addressType + '2']) {
        var val = place.address_components[i][componentForm2[addressType + '2']];
        document.getElementById(addressType + '2').value = val;
      }
    }
  document.getElementById('autocomplete2').value = 
    place.address_components[0]['long_name'] + ' ' +
    place.address_components[1]['long_name'];

  /*document.getElementById('route2').value = (document.getElementById('chbSame').checked ? document.getElementById('autocomplete2').value : '');*/
  document.getElementById('route2').value = '';
}
  // [END region_fillform]

// [START region_geolocation]
// Bias the autocomplete object to the user's geographical location,
// as supplied by the browser's 'navigator.geolocation' object.
function geolocate() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var geolocation = new google.maps.LatLng(
        position.coords.latitude, position.coords.longitude);
      var circle = new google.maps.Circle({
        center: geolocation,
        radius: position.coords.accuracy
      });
      autocomplete.setBounds(circle.getBounds());
    });
  }
}

function geolocate2() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var geolocation = new google.maps.LatLng(
          position.coords.latitude, position.coords.longitude);
        var circle = new google.maps.Circle({
          center: geolocation,
          radius: position.coords.accuracy
        });
        autocomplete2.setBounds(circle.getBounds());
      });
    }
  }
  // [END region_geolocation]
initialize();

document.querySelector('#chbSame').addEventListener('change', checkedAddr);

function checkedAddr() {
  if (document.getElementById('chbSame').checked) {
    document.getElementById('route2').value = document.getElementById('route').value;
    document.getElementById('locality2').value = document.getElementById('locality').value;
    document.getElementById('administrative_area_level_12').value = document.getElementById('administrative_area_level_1').value;
    document.getElementById('postal_code2').value = document.getElementById('postal_code').value;

document.getElementById('autocomplete2').value = document.getElementById('autocomplete').value;
  } else {
    }
}
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>

<body onload="initialize()">
<div class="clearfix">
 <label for="street_1">Mailing Address 1:</label>
 <input name="street_1" type="text" maxlength="120"  onfocus="geolocate()"  id="autocomplete"  size="54"  />
</div>

<div class="clearfix">
 <label for="m2street_1">Mailing Address 2:</label>
 <input name="m2street_1" type="text" maxlength="120"  size="54"  id="route"  />
</div>

<div class="clearfix">
 <label for="city_1">City:</label>
 <input name="city_1" type="text" maxlength="50"  size="30"  id="locality"  />

<div class="clearfix">
     <label for="state_1">State:</label>
     <input type="text" name="state_1"  id="administrative_area_level_1" size="8" maxlength="12">
    </div>

<div class="clearfix">
 <label for="street_1">Zip Code:</label>
 <input name="postal_1" type="text" maxlength="12"  size="8"  id="postal_code"  />
</div>

       <script type="text/javascript">
        function FillBilling_1(f) {
  if(f.billingtoo_1.checked == true) {
    f.pstreet_1.value = f.street_1.value;
 f.p2street_1.value = f.m2street_1.value;
    f.pcity_1.value = f.city_1.value;
 f.pstate_1.value = f.state_1.value;
 f.ppostal_1.value = f.postal_1.value;
  }
}
        </script>

<div class="clearfix">
 <input type="checkbox" name="billingtoo_1" onclick="FillBilling_1(this.form)" id="chbSame">
 <em>Check this box if Physical Address and Mailing Address are the same.</em>
</div>

<div class="clearfix">
 <label for="pstreet_1">Physical Address 1:</label>
 <input name="pstreet_1" type="text" maxlength="120"  onfocus="geolocate2()"  id="autocomplete2"  size="53"  />
</div> 

<div class="clearfix">
 <label for="p2street_1">Physical Address 2:</label>
 <input name="p2street_1" type="text" maxlength="120"  size="53"  id="route2"  />
</div>

<div class="clearfix">
 <label for="pcity_1">City:</label>
 <input name="pcity_1" type="text" maxlength="50"  size="30"  id="locality2"  />

<div class="clearfix">
     <label for="pstate_1">State:</label>
     <input type="text" name="pstate_1"  id="administrative_area_level_12" size="8" maxlength="12">
    </div>

<div class="clearfix">
 <label for="pstreet_1">Zip Code:</label>
 <input name="ppostal_1" type="text" maxlength="12"  size="8"  id="postal_code2"  />
</div>
 <br>
     <br>

<div class="clearfix">
 <label for="street_2">Mailing Address 1:</label>
 <input name="street_2" type="text" maxlength="120"  onfocus="geolocate()"  id="autocomplete"  size="54"  />
</div>

<div class="clearfix">
 <label for="m2street_2">Mailing Address 2:</label>
 <input name="m2street_2" type="text" maxlength="120"  size="54"  id="route"  />
</div>

<div class="clearfix">
 <label for="city_2">City:</label>
 <input name="city_2" type="text" maxlength="50"  size="30"  id="locality"  />

    <div class="clearfix">
     <label for="state_2">State:</label>
     <input type="text" name="state_2"  id="administrative_area_level_1" size="8" maxlength="12">
    </div>
        <div class="clearfix">
 <label for="street_2">Zip Code:</label>
 <input name="postal_2" type="text" maxlength="12"  size="8"  id="postal_code"  />
</div>

       <script type="text/javascript">
        function FillBilling_2(f) {
  if(f.billingtoo_2.checked == true) {
    f.pstreet_2.value = f.street_2.value;
 f.p2street_2.value = f.m2street_2.value;
    f.pcity_2.value = f.city_2.value;
 f.pstate_2.value = f.state_2.value;
 f.ppostal_2.value = f.postal_2.value;
  }
}
        </script>

<div class="clearfix">
 <input type="checkbox" name="billingtoo_2" onclick="FillBilling_2(this.form)" id="chbSame">
 <em>Check this box if Physical Address and Mailing Address are the same.</em>
</div>

<div class="clearfix">
 <label for="pstreet_2">Physical Address 1:</label>
 <input name="pstreet_2" type="text" maxlength="120"  onfocus="geolocate2()"  id="autocomplete2"  size="53"  />
</div> 

<div class="clearfix">
 <label for="p2street_2">Physical Address 2:</label>
 <input name="p2street_2" type="text" maxlength="120"  size="53"  id="route2"  />
</div>

<div class="clearfix">
 <label for="pcity_2">City:</label>
 <input name="pcity_2" type="text" maxlength="50"  size="30"  id="locality2"  />

    <div class="clearfix">
     <label for="pstate_2">State:</label>
     <input type="text" name="pstate_2"  id="administrative_area_level_12" size="8" maxlength="12">
    </div>

        <div class="clearfix">
 <label for="pstreet_2">Zip Code:</label>
 <input name="ppostal_2" type="text" maxlength="12"  size="8"  id="postal_code2"  />
</div>​
```