I have a really simple piece of code that is supposed to change the img src of my img called innings. It's pretty straightforward, that onclick I call the function changeImage, and depending on the current src of the image, I change it to the next iteration of images. The code looks like:
<script type="text/javascript" >
function changeImage() {
var mySrc = document.getElementById('inning');
alert(mySrc.src);
if (mySrc.src = "1st.png") {
alert('im in here');
mySrc.src = "2nd.png";
}
else if (mysrc.src = "2nd.png")
mysrc.src = "3rd.png";
else if (mysrc.src = "3rd.png")
mysrc.src = "4th.png";
else if (mysrc.src = "4th.png")
mysrc.src = "5th.png";
else if (mysrc.src = "5th.png")
mysrc.src = "6th.png";
else if (mysrc.src = "6th.png")
mysrc.src = "7th.png";
else if (mysrc.src = "7th.png")
mysrc.src = "8th.png";
else if (mysrc.src = "8th.png")
mysrc.src = "9th.png";
else if (mysrc.src = "9th.png")
mysrc.src = "10th.png";
else if (mysrc.src = "10th.png")
mysrc.src = "1st.png";
}
</script>
</head>
<body>
<center> <label>SlowPitch Player Rotation</label></center>
<br /><br />
<Center>
<img id="inning" src="1st.png"
onclick='changeImage()' />
</Center>
Now the problem I'm having is that every time I hit the image, the changeImage() function hits the alert, letting me know the src is still 1st.png; meanwhile my first alert tells me that I have 2nd.png as my src.
if (mySrc.src == "1st.png") {mysrc.getAttribute('src'), since themysrc.srcproperty (usually) returns an absolute path, even if the path in the attribute is relative. Also<label>is used to associate a form-element (input,selectortextarea) with a text-caption; and<center>is deprecated.