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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1137
  • Last Modified:

OnMouseDown event works in IE, but not in FireFox


Hi,

I have an image which triggers an onMouseDown Event. It works fine in IE, but not in Firefox, can someone tell me why?


<image src="https://gems.medicine.ufl.edu/gems/image/green<%=(8 +(j-1)*48)%>.jpg" border="0" onmousedown="on(this)"  ></td>


function on(mine)
{
         document.FellowWorkHours.elements[1].value = 0.5;
         mine.src='green.jpg';
}

0
penglu
Asked:
penglu
  • 3
1 Solution
 
justinbilligCommented:
it looks good to me without seeing the rest of your code

Are you genereating an error?
0
 
UnexplainedWaysCommented:
I tried your code but with a different image since i dont have yours and it worked.

So my guess, is that your getting the little [x] in the image?  If so, right click it and get the properties > url of the image and then put that in browser directly and see if it loads an image or still the [x] (probally a page not displayed actually).

[x], means that the code is working, but your not giving the right location to the file.
Image, maybe there is a problem with your "document.FellowWorkHours.elements[1].value = 0.5;" line, comment that out and try again.


Maybe try this to see if your calling the function first:

function on(mine)
{
   alert("function on(mine)");
         document.FellowWorkHours.elements[1].value = 0.5;
         mine.src='green.jpg';
}


Do you also need to change
mine.src='green.jpg';
to
mine.src='https://gems.medicine.ufl.edu/gems/image/green.jpg';








This is the code that i got it working with (Exactly the same!!!):
Only reason i post this is to show that the code is working, so it's a suttle error that were looking for.

<html>
<head>
<script language=javascript>

function on(mine)
{
         mine.src='img2.jpg';
}

</script>
</head>
<body>

<image src="img1.jpg" border="0" onmousedown="on(this)" ></td>

</body>
</html>


So try my ideas above and then post back and i'll see if i have any more ideas.
0
 
pengluAuthor Commented:

Thanks for the quick response. Actually, this is the complete code":

Fucntion on(mine)
{
        for(i=1; i<=336; i++)
       {
      if(location == 'abc')
      {
                document.FellowWorkHours.elements[i-1].value = 0.5;
                
                          // sh is a string variable
                          //  sh='https://gems.medicine.ufl.edu/gems/image/red'
                          mine.src=sh + i + '.jpg';
               }
     }
}


anything wrong with it?

0
 
UnexplainedWaysCommented:
//  sh='https://gems.medicine.ufl.edu/gems/image/red'

That would need to be uncommented, and a ; @ the end.


Try this, i've added a debug thing to make it easier to test the code.  If it's true. you'll get messages to see where the code is heading.  And i only use 3 loops because you dont want 600 messages!

This will let you know if the function is called, what is happening in the function's and might give you an idea on where the problem is.

So first, is the function being called then

If location = abc, then what is the src that your putting into the image
if false, then why was it false.




var DEBUG = true;
//var DEBUG = false;

Fucntion on(mine)
{
      if(DEBUG)
      alert("Fucntion on("+mine+")");
      var times = 336;

      if(DEBUG)
      {
          times = 3;
      }

      for(i=1; i<=times ; i++)
     {
          if(location == 'abc')
          {
               document.FellowWorkHours.elements[i-1].value = 0.5;
               
                          // sh is a string variable
                          //  sh='https://gems.medicine.ufl.edu/gems/image/red'
                          if(DEBUG)
                                alert("SRC: "+sh+i+".jpg");
                          mine.src=sh + i + '.jpg';
           }
           else
           {
               if(DEBUG)
                   alert("FAILED: if("+location +"== 'abc')");
           }
     }
}
0
 
UnexplainedWaysCommented:
Well it would of been nice for a reply so could of known if my code helped or not.

The code itself worked, but i dont know about there site.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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