'Dynamic image change according to internal variable

I have 2 images with different names run0.png and run1.png this phrase (:="start_main_m":) which comes after "run" is an internal variable and changes automatically between 1 and 0 from inside the codethus gives the names run1 and run0.

<img border="0" src="pics/run:="start_main_m":.png" width="32" height="32">

With a simple code in HTML, this image changes but only after refreshing the page. I want to change between these 2 images without refreshing the page. I have tried using if condition and setinterval() function but it doesn't change anything and still needs to be refreshed to change the image. It seems like I need to use a kind of for loop condition but don't know how?!?!

function changepic() {
    if (:="start_main_m":==1) {
        document.getElementById("AM").src = "pics/run1.png"
    } else {
        document.getElementById("AM").src = "pics/run0.png"
    }
}

setInterval("changepic()", 500);
<img id="AM" border="0" src="pics/switch0.png" width="105" height="80">

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source