Alright so i need to know if its possible to alert the user that the url of the image is invalid (assuming they have entered it incorrectly).
What the code does is that the user enters the image number. Presses display and the image will show below so they can download.
The image is provided bya website, that is why if the image code is incorrect, the user must be alerted.
Please run the code snippet.
For a legit image enter 63700 on the textbox.
Now enter a random number or word... nothing shows up? the user needs to be alerted. I hope i'm making sense.
function myFunction() {
var x = document.getElementById("imagetxt").value;
var y = "http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-" + x + ".jpg"
document.getElementById("image1").src = y;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body align="center">
<form>
<input id="imagetxt" size="6" type="text" value="">
<input type="button" value="Display" onclick="myFunction()">
</form>
<img id="image1" src="" width="50%" height="50%">
</body>
</html>