I have a JSON database with information that I would like to autofill in my JavaScript/HTML if a particular element in the array is found. I have an handler event, onchange to listen if that particular element is found, it prints all of the info of that particular array. I have it printing into the console, but how would I go about printing this onto my relevant HTML sections?
JavaScript:
const getAssetInfo = id => {
$.get( "http://localhost:3000/assets/" + id, function( data ) {
console.log(data);
});
}
$('document').ready(() => {
<td><input id='asset_tag_no${count}' type='text' onchange = "getAssetInfo(this.value);" bottom required /></td>
<td><input id='manufacturer_serial_no${count}' type='text' bottom required/></td>
<td><textarea id='description${count}' type='text' bottom required description></textarea></td>
}
let data = [];
// Store all Info from this row
let assetInfo = {
asset_tag_no: $(`#asset_tag_no${i}`).val(),
manufacturer: $(`#manufacturer_serial_no${i}`).val(),
descriptions: $(`#description${i}`).val(),
costs: $(`#cost${i}`).val(),
po_no: $(`#po_no${i}`).val(),
remarks: $(`#remarks${i}`).val(),
}
}
JSON in the database
{
"assets" : [
{
"id": "0946",
"description" : "SONY - Camera",
"manufacturer" : "SONY",
}
}
Screenshot of console returning data and an example of the desired input population:

onReadyfunction looks very weird since it just contains html which isn't valid javascript. So... can you explain what you see as not working and maybe what you expect to see when things are working?$.getreturns some data, right?asset_tag_no${count}, I assume that the first one isasset_tag_no0and thenasset_tag_no1corresponding to the table row count? Is it possible to use the assetidthere instead? If not, there's a little more work to figure out which row is the right one to update. I'm not sure how much control you have over the html in this problem.