JSFiddle - React, Tailwind, and code Playground
HTML
<form action="submitPage.php" method="post" onsubmit="savePathInVar();">
<table>
<tr>
<td><img src="http://placehold.it/350x150" onclick="changecolor(this);" /></td>
<td><img src="http://placehold.it/350x150" onclick="changecolor(this);" /></td>
</tr>
<input value="ClickedImaged" id="hiddenImgLoc"/>
<input type="submit" value="Submit" />
</table>
</form>
JavaScript
changecolor = function(img)
{
var images = document.getElementsByTagName("img");
for(var i=0,j=images.length; i<j; i++)
{
images[i].style.borderColor="#000";
}
img.style.borderColor="#F00";
//Operate on img location as before
savePathInVar(img.src);
}
function savePathInVar(ImgLocation)
{
document.getElementById('hiddenImgLoc').value = ImgLocation
}