What I observe is that the value only changes during the execution of the function and then returns to the original value, or else this execution (onload) is made after reading the global variable. I need only one statement: How do I test if an image (jpg) was loaded successfully and then use that value shortly after the check. I have tried everything (two days), until I used dynamic form element creation during the function execution (input value), and even then the value of the inputs DO NOT CHANGE to be read after the function. Oh, and before lowering my reputation again, consider that I do not speak English and live in the underdeveloped belt of the globe.
var imagem = '0';
var myImg = new Image();
myImg.src = 'Alfabeto-0002.jpg';
myImg.onload = function(){
document.write('Image Loaded');
imagem='1';
}
myImg.onerror = function(){
document.write('Image NOT Loaded');
imagem='2';
}
alert(imagem);