Fairly new to JS, trying to build a tool for the company that i work for, that can pull the image from the supplier website when user types in a product number, the code below somewhat works but the image doesn't get replaced when entering a new number.
HTML:
<input id='pCOde' placeholder='Code?'>
<button onclick='addImg()'> Click me </button>
<p id='hImg'></p>
Javascript:
const pCode = document.getElementById("pCode").value;
function addImg() {
const img = new Image();
img.src = 'https://SupplierWebsite/pics/' + pCode.value + '.JPG';
document.getElementById('hImg').replaceWith(img);
img.style.height = 'auto';
img.style.width = '85%';
}
Eventually wanted to pull more data from the supplier site, such as product title and price but this seems even trickier.