json data to button function

json data to button function

Sorry, I'm sort of new to JSON, but I am somewhat familiar with jQuery.  I've mainly only used jQuery to manipulate the DOM here and there, but nothing too advanced.  I have a working piece of code that pulls data from a web method and puts it into a modal popup using bootstrap 3.  What I'm trying to figure out is how to add a button and a function to that button to populate the textboxes on the page with the data when submitted.


  1. <script>
  2.         $(document).ready(function () {
  3.             // Add the page method call as an onclick handler for the div.
  4.             $("#LoadExistingAddresses").click(function () {
  5.                 $.ajax({
  6.                     type: "POST",
  7.                     url: "Beneficiary.aspx/GetAddresses",
  8.                     data: "{}",
  9.                     contentType: "application/json; charset=utf-8",
  10.                     dataType: "json",
  11.                     success: function (msg) {
  12.                         var dataObj = $.parseJSON(msg.d);
  13.                         var tempText = '<div class="row">';
  14.                         $.each(dataObj, function (i, item) {
  15.                             tempText = tempText + '<div class="col-xs-12 col-sm-6">';
  16.                             tempText = tempText + '<h5>' + item.FullName + '</h5>';
  17.                             tempText = tempText + '<p>' + item.AddressFormatted + '</p>';
  18.                             tempText = tempText + '<p><button type="button" class="btn btn-primary">Use This Address</button>'
  19.                             tempText = tempText + '</div>';
  20.                             tempText = tempText + '<div class="col-xs-12 visible-xs">&nbsp;</div>';
  21.                         });
  22.                         tempText = tempText + '</div>';
  23.                         $('#modal-body-address-list').html(tempText);
  24.                         $('#addresses').modal();
  25.                     }
  26.                 });
  27.             });
  28.         });
  29.     </script>

What type of function do I need to create to pass in the item so when someone clicks on "Use This Address" the address fields on the page get populated with my data.  I have:
item.Address1, item.Address2, item.City, item.State, item.ZipFormatted properties along with the item.AddressFormatted property.  Also, the item.State will point to a dropdown list where the text and value matches the 2 lettered US state.