Using Javascript to change an Image src -


i have simple piece of code supposed change img src of img called innings. it's pretty straightforward, onclick call function changeimage, , depending on current src of image, change next iteration of images. 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 problem i'm having every time hit image, changeimage() function hits alert, letting me know src still 1st.png; meanwhile first alert tells me have 2nd.png src.

you using = assignment. value getting assigned variable; want check equality in if statements. use either == (are equal?) or === (are equal , same type?).


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -