473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

JS, MousePosition and storing -

1
Hi,

I'll be honest I'm a newbie at all this and I'm need to get a small JS working as soon as possible - please can anybody help? I have a small insentive if needed ;)

What i need is a spot the ball page. An image on a HTML page that on mouse press stores to position of the crosshair into a X and Y box and works for most browers if not all of them.

Similiar to this:

************************************

[HTML]<!--
================================================== ==========
Capturing The Mouse Position in IE4-6 & NS4-6
(C) 2000 www.CodeLifter.com
Free for all users, but leave in this header
//-->

<html>
<body>

<!-- Part One:
Set up a form named "Show" with text fields named "MouseX"
and "MouseY". Note in the getMouseXY() function how fields
are addressed, thus: document.FormName.FieldName.value
//-->

<form name="Show">
<input type="text" name="MouseX" value="0" size="4"> X<br>
<input type="text" name="MouseY" value="0" size="4"> Y<br>
</form>

<!-- Part Two:
Use JavaScript ver 1.2 so older browsers ignore the script.
The &lt;script> must be *after* the &lt;form> -- since the form
and fields must exist *prior* to being called in the script.
//-->

<script language="JavaScript1.2">
<!--
[/HTML]
Expand|Select|Wrap|Line Numbers
  1. // Detect if the browser is IE or not.
  2. // If it is not IE, we assume that the browser is NS.
  3. var IE = document.all?true:false
  4.  
  5. // If NS -- that is, !IE -- then set up for mouse capture
  6. if (!IE) document.captureEvents(Event.MOUSEMOVE)
  7.  
  8. // Set-up to use getMouseXY function onMouseMove
  9. document.onmousemove = getMouseXY;
  10.  
  11. // Temporary variables to hold mouse x-y pos.s
  12. var tempX = 0
  13. var tempY = 0
  14.  
  15. // Main function to retrieve mouse x-y pos.s
  16.  
  17. function getMouseXY(e) {
  18.   if (IE) { // grab the x-y pos.s if browser is IE
  19.     tempX = event.clientX + document.body.scrollLeft
  20.     tempY = event.clientY + document.body.scrollTop
  21.   } else {  // grab the x-y pos.s if browser is NS
  22.     tempX = e.pageX
  23.     tempY = e.pageY
  24.   }  
  25.   // catch possible negative values in NS4
  26.   if (tempX < 0){tempX = 0}
  27.   if (tempY < 0){tempY = 0}  
  28.   // show the position values in the form named Show
  29.   // in the text fields named MouseX and MouseY
  30.   document.Show.MouseX.value = tempX
  31.   document.Show.MouseY.value = tempY
  32.   return true
  33. }
  34.  
  35. //-->
  36.  
[HTML]</script>
</body>
</html>[/HTML]

************************

This code above is almost perfect apart from that I need to be able to put a crosshair on the screen and that then popultaes the X & Y boxes with the co-ordinates but the above code updates the box each time the mouse moves.

THIS IS A NICE TO HAVE BUT NOT MUST:
I would also like to be able to integrate the X & Y boxes so that the users can press a button ("play") and the variables of the X & Y boxes are stored in the shopping cart (Paypals or other) and the users can then play again.


I know this is probably asking alot but please can anybody help?

Many Thanks
Dan
Sep 20 '05 #1
1 3533
acoder
16,027 Expert Mod 8TB
For the mouse position, see this link.
Oct 1 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mark | last post by:
I have a website with an increasing amount of articles and news reports and so I am thinking of moving away from storing each article as a seperate page to having a single page and storing articles...
4
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
3
by: Dade Murphy | last post by:
Hi everyone! I've got a little problem and just cann't find any solution for it: I need to get the current position of the mousecursor at my webpage for some overlay stuff. Currently I use the...
5
by: Don Vaillancourt | last post by:
I'm building a system when one can upload a document to the website. I will be storing the document on the hard-drive for quick/easy access, but I was also thinking of storing it in an existing...
1
by: Scatropolis | last post by:
How do I set the MousePosition? I found MousePosition but it says it can't modified it because it isn't a variable. thanks
7
by: iwdu15 | last post by:
hi, im trying to egt a picturebox to follow the mousecursor around in a certain area, but the picturebox isnt where the mouse is...how can i get the picturebox to be where the mouse cursor is?...
6
by: (PeteCresswell) | last post by:
User wants to go this route instead of storing pointers in the DB and the documents outside. Only time I tried it was with only MS Word docs - and that was a loooong time ago - and it seemed to...
1
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
When using Control.MousePosition the x values seems to be just fine when I draw something on the screen, but the Y value seems to have got an offset - independently of where on the screen I put the...
2
by: Mythran | last post by:
We followed an example found on MSDN to create an encrypted FormsAuthenticationTicket and storing the ticket in a cookie. Is this the "correct" way to store the authentication ticket? We are...
2
by: ducttape | last post by:
Hello I'm busy working with an MDI parent and child forms. I've found that there is a discrepancy between the locations returned by DesktopLocation, Control.MousePosition and MouseEventArgs...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.