Google Answers Logo
View Question
 
Q: Javascript mouse event ( No Answer,   3 Comments )
Question  
Subject: Javascript mouse event
Category: Computers > Programming
Asked by: universityresource-ga
List Price: $5.00
Posted: 09 Nov 2004 10:55 PST
Expires: 09 Dec 2004 10:55 PST
Question ID: 426713
Hi,
I would like to find a javascript example that does the following:
On an HTML page in a regular browser (explorer, navigator) 
A user clicks on an image, and moves the mouse over to another image
and releases the mouse.
The javascript calls a url sending the id of the first image and the
id of the second image.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Javascript mouse event
From: duelin-ga on 17 Nov 2004 20:23 PST
 
The below works in IE6 and Firefox 1.0 (Mozilla ... same DOM & event
model as Netscape).  The return false in onmousedown keeps Mozilla
from starting the user on dragging the image.  The return false in
ondragstart does the same for IE.  I don't think anything relevant to
this has changed in recent versions of these browsers so it should
work in IE4+ and NN6+, but you should test on versions that matter to
you.

<html>
 <head>
  <script>
   var downId;
   var upId;
   function doIt() {
    location.href="whatever-page.html?downId="+downId+"&upId="+upId;
   }
  </script>
 </head>
 <body>
  <img 
   src="http://answers.google.com/answers/answers-logo-sm.gif"
   id="logo1"
   onmousedown="window.status='that was down';downId='logo1';return false;"
   ondragstart="return false;"
   onmouseup="window.status='that was up';upId='logo1';doIt();">
  <hr>
  <img 
   src="http://answers.google.com/answers/answers-logo-sm.gif"
   id="logo2"
   onmousedown="window.status='that was down';downId='logo2';return false;"
   ondragstart="return false;"
   onmouseup="window.status='that was up';upId='logo2';doIt();">
 </body>
</html>
Subject: Re: Javascript mouse event
From: starlucky-ga on 18 Nov 2004 15:06 PST
 
Try this out.  You can click one image, then click the other image,
and the 2nd clicked image becomes the first one.  You may need to
change the names of the images.  You can add more images to swap if
you would like.  If you need help with this script, tell me.

See a working version of this at:  http://gvc.gotdns.com/greg/lol.htm

I hope this is what you wanted.



<html>
<head>
<title>Image Move Test</title>

<script language="javascript" type="text/javascript">


// Make a temporary variable
source = new Image

// Make a var to distinguish between source and destination image
var doswitch=false;

</script>


</head>



<body>


<img name="book1" src="book.jpg"
onclick="if(doswitch==false){source.src=document.book1.src;
doswitch=true;}else{document.book1.src=source.src; doswitch=false;}">

<p>

<img name="book2" src="book2.png"
onclick="if(doswitch==false){source.src=document.book2.src;
doswitch=true;}else{document.book2.src=source.src; doswitch=false;}">


</body>
</html>
Subject: Re: Javascript mouse event
From: universityresource-ga on 23 Nov 2004 06:08 PST
 
Thanks. This and some other material provided a solution.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy