473,779 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JS, MousePosition and storing -

1 New Member
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.FormNa me.FieldName.va lue
//-->

<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="JavaS cript1.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 3570
acoder
16,027 Recognized Expert Moderator MVP
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
3063
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 in a databasewhich are retrieved using a GET parameter. I see the advantage to me in using this approach as being making use of MySQL's fulltext search capability and less work needed when updating the design of the page. I'm not sure of a few...
4
3884
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 new site I goto seems to prompt me to store their cookie. The other is Pocket IE on Pocket PC 2002, with the cookies set to 'enabled'. My problem is that the cookies dont seem to be being written with my ASP. I dont get the prompt to store...
3
1572
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 following code for this: if (ieDom) { // Internet Explorer X=window.event.clientX + document.body.scrollLeft;
5
2146
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 database since most of the sites information is all stored there. As well there would be only one place to worry about backing up. And if the file on the hard-drive was ever missing or became corrupted, I could restore it form tha database. Is...
1
3165
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
7619
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? thanks -- -iwdu15
6
3199
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 me like there were performance issues at the time. How about the different types? The MS docs I would expect Access to differentiate and handle appropriately (i.e. .DOC and .XLS).. but how about ..PDF? and can I stash a .TXT document in the...
1
3696
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 cursor the item I draw is a fixed offset below the cursor - why is this so?
2
2007
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 attempting to create a web service from the web application and our goal is to have the user login to the web application and then, using the same credentials and/or authentication objects, access the web services to retrieve our data from other...
2
5460
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 e.Location, but I can't work out why or what exactly the discrepancy is. My forms are all custom without title bars and thus I've had to create my own moving methods, etc. This is obviously related to the location of the mouse pointer. My mouse...
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10139
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9931
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.