Ok so I have a JavaScript function that swaps the src
of two images which swaps the images themselves no problem. However, I have two values that need switched along with the images themselves so I can later add the values up correctly. An example being,
img src="ble.jpg" id="F" value="" onclick="swap(5)"
img src="ilk.jpg" id="4" value="2" onclick="swap(6)"
So, I want to swap the above values as well so that the first image obtains a value of "2" and the second a value of "". Is there a way to do this? I have been trying to figure out a way for days and it just isn't clicking.
Here is the function to swap images:
var toggle=0;
var saveNum;
var pic="0";
function swap (elem)
{
if (toggle == 0)
{
saveNum = elem;
pic = document.images[parseInt(elem)].src;
toggle++;
}
else
{
hold = document.images[parseInt(elem)].src;
document.images[parseInt(elem)].src = pic;
document.images[parseInt(saveNum)].src = hold;
toggle = 0;
}
}