I am attempting to make a webpage with 25 images where one image is displayed at a time. The 25 images are all combinations of two sets of five items. In this case the two sets are (ant, blueberry, ladybug, marshmallow, mushroom) and (blimp, truck, moon, ocean, redwood), so for instance one image would be "ant + blimp", another image would be "ant + truck" etc. The idea is to have a button for each thing, and as users click each button, the appropriate image would be called up.
I am a novice with javascript.
I have the images sorted into five different folders, each named after the first set of things, and in each folder the image is named XXXX.png, where XXXX is something in the second set of things.
I have made buttons like this:
<button onclick="smallFunction('ant')">Ant</button>
<button onclick="smallFunction('blueberry')">Blueberry</button>
<button onclick="smallFunction('ladybug')">Ladybug</button>
<button onclick="smallFunction('marshmallow')">Marshmallow</button>
<button onclick="smallFunction('mushroom')">Mushroom</button>
<p>
<img id="thepic" src="round1/ladybug/blimp.png" style="width:80%"><p>
<button onclick="bigFunction('blimp')">Blimp</button>
<button onclick="bigFunction('truck')">Cement Truck</button>
<button onclick="bigFunction('moon')">The Moon</button>
<button onclick="bigFunction('ocean')">The Pacific Ocean</button>
<button onclick="bigFunction('redwood')">Redwood Tree</button>
<p>
and below that I have the following Javascript:
<script>
var small;
var big;
var small = "mushroom";
var big = "truck";
function smallFunction(x){
small = x;
}
function bigFunction(y){
big = y;
}
document.getElementById("thepic").src = "round1/" + small + "/" + big + ".png";
</script>
The site, as it currently is working, can call up the initially set image (the mushroom + truck image), but clicking the buttons does nothing.
I suspect the problem is that the page is not repeatedly processing the img src line, so even as the variables change, the image is not updating. Is that correct? If so, how do I fix that?
It's also possible the variables aren't actually changing with the code I've written.
This is the site (not quite) in action: http://www.smallthingseatingbigthings.com/