I am a C programmer trying to fix a bug in some code I did not create. When a row of a table is clicked, it sets the image with id 'square'
$('#square').attr("src","image/"+row.id+"_2_1.jpg");
However, some images are named _3_1.jpg (not under my control) so I would like to check if the _2_ image exists and if not, load a _3_ variant.
Using "onerror" doesn't seem to work and inserting an IF statement stops the entire table from loading.
This is the whole function:
$('#table').on('click-row.bs.table', function (e, row, $element) {
if(config["homing_tool"] == "1"){
$('#detail').show();
$('#detail1').hide();
$('#detail2').hide();
$('.homing').hide();
}else{
$('#detail').show();
$('#detail1').show();
$('#detail2').show();
$('#iris').attr("src","image/"+row.id+"_0_1.jpg");
$('#square').attr("src","image/"+row.id+"_2_1.jpg");
};
var x;
for (x in row) {
if(x == "type"){
$('#'+x).html(spec[row[x]]["name"]);
}else{
$('#'+x).html(row[x]);
}
}
});
Edit: Thanks for the suggestions! All data is local, so no need for connecting to servers and using HTTP requests as far as I know. I will try the other suggestions tomorrow. The PC I have to access remotely is 6 hours ahead of me and they just shut down for the day.