• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Change Picture Displayed with Mouse click

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
dzirkelb
Asked:
dzirkelb
  • 3
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
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
 
dzirkelbAuthor Commented:
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
 
leakim971PluritechnicianCommented:
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
 
dzirkelbAuthor Commented:
Yup, that did the trick...thanks!!
0
 
leakim971PluritechnicianCommented:
You're welcome! Thanks for the points!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now