javascript - How to change image of other buttons on onClick event? -


I am again with a problem

I have four buttons, when I click on a button Clicking, this button converts image from old image to new image right now the image changes, but if I press the button 2 button button 2 changes, but the image of the button is the same image as new i Here's the code I want to return to the old image:

  & lt; Input type = "image" id = "start" src = "buttonred.png" width = "50px" height = "50px" onClick = "this.src = 'buttonblue.png'" /> & Lt; Input type = "image" id = "stop" src = "buttonred.png" width = "50px" height = "50px" onClick = "this.src = 'buttonblue.png'" /> & Lt; Input type = "image" id = "slow" img src = "buttonred.png" width = "50px" height = "50px" onClick = "this.src = 'buttonblue.png'" /> & Lt; Input type = "image" id = "fast" img src = "buttonred.png" width = "50px" height = "50px" onClick = "this.src = 'buttonblue.png'" />    

It typed and tested in Notepad.

This essentially searches for string value and changes it with the buttonblu and vice versa.

  & lt; Input type = "image" id = "start" src = "buttonred.png" width = "50px" height = "50px" onClick = "Change color (this.id)" /> & Lt; Input type = "image" id = "stop" src = "buttonred.png" width = "50px" height = "50px" onClick = "Change color (this.id)" /> & Lt; Input type = "image" id = "slow" src = "buttonred.png" width = "50px" height = "50px" onClick = "Change color (this.id)" /> & Lt; Input type = "image" id = "fast" src = "buttonred.png" width = "50px" height = "50px" onClick = "Change color (this.id)" /> & Lt; Script & gt; Change function color (id) {var btn = document.getElementById (id); If (btn.src.match (/ buttonred / gi)! = Null) {btn.src = btn.src.replace ("buttonred.png", "buttonblue.png"); } Other {btn.src = btn.src.replace ("buttonblue.png", "buttonred.png"); }} & lt; / Script & gt;    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -