There is a function building table.
This function is called when the page loads.

var strResult = ""; $.each(contacts, function (index, contact) { strResult += "<div class=\"row\">"; strResult += "<input class=\"form-control\" value=\"" + contact.ID + "\"/><input id=\"first_name+" + contact.ContactID + "\" class=\"form-control\" value=\"" + contact.first_name + "\"/>; strResult += "<button name=\"del=" + contact.ContactID + "\" data-action=\"Delete\" class=\"btn btn-default btnDel\"><span class=\"glyphicon glyphicon-remove\"></span></button>"; strResult += "</div>" }); $("#divResult").html(strResult); 

And the button which click is processed here

 $('body').on('click', '.btnsv', function () { var id = CutId(this.name); // обрезка id имя кнопки var contact = // здесь хочется, чтобы данные из input first_name + contactID записывались сюда $.ajax({ url: 'http://localhost:55285/api/values/', type: 'POST', data: JSON.stringify(contact), contentType: 'application/json; charset=utf-8', success: function (data) { }, error: function (x, y, z) { alert(x + '\n' + y + '\n' + z); } }); }); 

Tell me, please, how to do it

 $('#first_name+' + id).val() // не работает 
  • не работает. what exactly is expressed? Any errors betrays or begins to run in shorts around the house and scream - help rape? - Alexey Shimansky
  • writes that the variable is undefined. - 2felix
  • well see why your CutId nothing .... - Alexey Shimansky
  • The CutId function returns a value. She is simply not represented here. - 2felix
  • one
    Invalid character in identifier. I didn’t even notice it) I’m writing correctly on the machine, lol - Aleksey Shimansky

1 answer 1

 <input id=\"first_name+" + contact.ContactID + "\" class=\"form-control\" value=\"" + contact.first_name + "\"/> 

In this line in id = \ "first_name +" there is an invalid character in the identifier, correctly like this.

  <input id=\"first_name" + contact.ContactID + "\" class=\"form-control\" value=\"" + contact.first_name + "\"/> 

thank you Alexey Shimansky