I have some code that displays the JSON and allows the user to edit the text. After editing, I want to allow the user to click a button to save the new input value. Everything works as expected except for grabbing that new input value.
for (let i = 0; i < jsonObject.results.length; i++) {
var row = `<tr scope="row" class="test-row-${jsonObject.results[i].id}">
<td id="fName-${jsonObject.results[i].id}" data-testid="${jsonObject.results[i].id}">${jsonObject.results[i].firstName}</td>
// some code
$(`#save-${jsonObject.results[i].id}`).click(function(){
clickAButton(jsonObject.results[i].id, jsonObject, i);
});
$(`#fName-${jsonObject.results[i].id}`).on('click', editResult)
}
function editResult(){
var testid = $(this).data('testid')
var value = $(this).html()
$(this).unbind()
$(this).html(`<input class="result form-control" data-testid="${testid}" type="text" value="${value}">`)
}
function clickAButton() {
var text = $(`#fName-${jsonObject.results[index].id}`).val();
console.log("text from " + text);
// code
}
the code above displays
text from
How do I get it to display the new user input?