I'm trying to make the background change images based on the number of clicks I need (I know the code is not great since I have to state for every picture, but I only need 4 images because only 3 total button clicks from any of the 3 buttons are needed). Basically, I have a set of 3 buttons, and what I would like my code to do is to change background images based on the total amount of clicks from all three. Please suggest jQuery if you wish, but I don't want to use jQuery because I'd rather get used to JavaScript first. The JavaScript function doesn't seem to count anything, and it did work for only one button. Thanks! :)
<!DOCTYPE html>
<html>
<body>
<script language="JavaScript" type="text/javascript">
var noOfInputs = 0;
function buttons_click () {
noOfInputs++;
if(noOfInputs === "0") {
window.document.getElementById('myImage').src="Number0.jpg";
}
if(noOfInputs === "1") {
window.document.getElementById('myImage').src="Number1.jpg";
}
if(noOfInputs === "2") {
window.document.getElementById('myImage').src="Number2.jpg";
}
if(noOfInputs === "3") {
window.document.getElementById('myImage').src="Number3.jpg";
}
}
</script>
<button>1</button>
<button>2</button>
<button>3</button>
<img id="myImage" src="Number0.jpg" style="width:400px">
<button onclick="document.getElementById('myImage').src='Number0.jpg'">Cancel</button>
</body>
</html>
Please go easy on me...I'm very prone to beginner mistakes (cause I'm a beginner). All help is greatly appreciated :)