I am facing trouble in getting the attributes in itemIMG to change when the button is clicked.
This is the code in my js, it is in a loop:
$("#btnitemIMGcolour").click(function(){
$("#itemIMG").attr("src", serverURL() + "/images/" + arr[i].itemColour);
}
This is the code for the button to function window.location:
$('#btnitemIMGcolour' + arr[i].colourID).bind("click", {id1: arr[i].itemID, id2: arr[i].colourID}, function (event) { //This line of code create a button and has an event listener
var data = event.data;
displayothercolour(data.id1, data.id2); // Call shoecat function
});
function displayothercolour(itemID,colourID) {
window.location = "itemdetail.html?itemID=" + itemID + "&colourID=" + colourID;
localStorage.setItem("colourID", colourID);
}
The codes works, however the image currently only show the latest image inserted in the database.
The full loop is shown below:
function _getitemcolour(arr) {
var i;
for (i = 0; i < arr.length; i++) {
$("#btnitemIMGcolour").click(function () {
$("#itemIMG").attr("src", serverURL() + "/images/" + arr[i].itemColour);
}
var t;
t = "<a href='#' id='btnitemIMGcolour" + arr[i].colourID + "'> <img src='" + serverURL() + "/images/" + arr[i].itemColour + "' class='itemIMGcolour'>";
$("#itemIMGcolour").append(t);
$('#btnitemIMGcolour' + arr[i].colourID).bind("click", { id1: arr[i].itemID, id2: arr[i].colourID }, function (event) { //This line of code create a button and has an event listener
var data = event.data;
displayothercolour(data.id1, data.id2); // Call shoecat function
});
}
}
function displayothercolour(itemID, colourID) {
window.location = "itemdetail.html?itemID=" + itemID + "&colourID=" + colourID;
localStorage.setItem("colourID", colourID);
}