[Last Call] Learn how to a build a cloud-first strategyRegister Now


Change Picture Displayed with Mouse click

Posted on 2010-01-08
Medium Priority
Last Modified: 2013-11-23
I am having troubles getting my code to change back and forth by clicking on a mouse button on an img.  Here is the javascript function:

function ShowOpenPOs(i, PartID)
    var url="PastDueOpenOrders-OpenPOs.asp?ID="+PartID
    if (document.images["imgPlusMinus"+i].src = "images/Plus.jpg")
        document.images["imgPlusMinus"+i].src = "images/Minus.jpg"
        document.images["imgPlusMinus"+i].src = "images/Plus.jpg"
      intI = i
    xmlHttp.open("GET", url , true)

Here is the img:

<img id="imgPlusMinus<%=i%>" alt="Show Open PO Details" src="images/test.jpg" onclick="ShowOpenPOs(<%=i%>, <%=rs1("ID")%>)">

What happens from my troubleshooting is when it is a plus and then clicked, it goes to a minus...perfect.  Now, when I click it when it is a minus, it goes to a plus, then right back to a minus.  What am I doing wrong?
Question by:dzirkelb
  • 3
  • 2
LVL 83

Expert Comment

ID: 26218610
Hello dzirkelb,

>Now, when I click it when it is a minus, it goes to a plus, then right back to a minus
Do you have the alert("Minus") too ?


Author Comment

ID: 26227018
Nope, it never gets to the alert...I've put all sorts of stuff in that section of the else statement just to test if it gets there, but it seems to not even get to that portion.
LVL 83

Accepted Solution

leakim971 earned 500 total points
ID: 26227385
Here :

Use double equal operator : ==
Else the test is always true ;-)
if (document.images["imgPlusMinus"+i].src == "images/Plus.jpg")

Open in new window


Author Closing Comment

ID: 31674817
Yup, that did the trick...thanks!!
LVL 83

Expert Comment

ID: 26234201
You're welcome! Thanks for the points!

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question