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

x
?
Solved

Change Picture Displayed with Mouse click

Posted on 2010-01-08
5
Medium Priority
?
297 Views
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:

[code]
function ShowOpenPOs(i, PartID)
{
    var url="PastDueOpenOrders-OpenPOs.asp?ID="+PartID
   
   
   
    if (document.images["imgPlusMinus"+i].src = "images/Plus.jpg")
    {
          alert(document.images["imgPlusMinus"+i].src)
        document.images["imgPlusMinus"+i].src = "images/Minus.jpg"
        alert(document.images["imgPlusMinus"+i].src)
    }else{
          alert("Minus")
        document.images["imgPlusMinus"+i].src = "images/Plus.jpg"
    }
   
      
      intI = i
    xmlHttp=GetXmlHttpObject(stateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
}
[/code]

Here is the img:

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

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?
0
Comment
Question by:dzirkelb
  • 3
  • 2
5 Comments
 
LVL 83

Expert Comment

by:leakim971
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 ?

Regards.
0
 

Author Comment

by:dzirkelb
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.
0
 
LVL 83

Accepted Solution

by:
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

0
 

Author Closing Comment

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

Expert Comment

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

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