I am loading images using javascript. All images are in sequence number. Images sometimes load some times do not.
Below are the functions.
function onLoad(){
window.resizeTo( 1100,600 )
var ans = ['a','b','c','d','e'];
var fsObj = new Image();

for(var a in ans){
fsObj.src = '/images/testquestion/' + questionNumber + '_' + ans[a] + '.jpg';
if (fsObj.width > 100) {
document.getElementById('question').src = fsObj.src;
realAns[questionNumber]= ans[a];
break;
}
}

}

function loadNextQuestion(){

questionNumber = questionNumber + 1; //first already loaded.
var ans = ['a','b','c','d','e'];
var fsObj = new Image();
for(var a in ans){
fsObj.src = '/images/testquestion/' + questionNumber + '_' + ans[a] + '.jpg';
alert(fsObj.width);
if (fsObj.width >= 100) {
document.getElementById('question').src = fsObj.src;
realAns[questionNumber]= ans[a];
break;
}
}
}


If I check fsObj.width it shows wrong for the images it does not load. Also if I add some alert before if condition it will work for few images that was not working earlier. I tried flushing Image() object but did not work. Seems something tricky and strange too.