I am new to javascript, and although there are many more complex solutions, I do not understand them and hope that I do not need at this point.
I have a basic picture ...
<img src="main-picture.jpg" name="Mainpic" id="image">
... and I want to be able to change this image when I click on one of two thumbnails.
<a href="" onclick="FirstPic()"><img src="replacement1.jpg" name="pic1"></a> <a href="" onclick="SecPic()"><img src="replacement2.jpg" name="pic2"></a>
My javascript code, I thought, would be very easy. I am currently using ...
function FirstPic(){ document.Mainpic.src = document.pic1.src return } function SecPic(){ document.Mainpic.src = document.pic2.src return }
Now the variable is changing , but it has not remained changed. When a thumbnail is pressed, a replacement picture blinks on the screen, and then returns to the original main image .jpg.
How to make a change permanent until another thumbnail is clicked?
Thanks!
javascript variables image src
Carriag
source share