# I want to get two seperate instances of cursor values in my clientX/Y; method in JavaScript

**URL:** https://forum.kirupa.com/t/i-want-to-get-two-seperate-instances-of-cursor-values-in-my-clientx-y-method-in-javascript/645929
**Category:** programming
**Created:** [February 1, 2021, 12:52am UTC](https://forum.kirupa.com/t/i-want-to-get-two-seperate-instances-of-cursor-values-in-my-clientx-y-method-in-javascript/645929 "2021-02-01T00:52:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Fejiro\_Eruotor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/fejiro_eruotor/32/13483_2.png) [@Fejiro\_Eruotor](https://forum.kirupa.com/u/Fejiro_Eruotor)
#### Post date: [February 1, 2021, 12:52am UTC](https://forum.kirupa.com/t/i-want-to-get-two-seperate-instances-of-cursor-values-in-my-clientx-y-method-in-javascript/645929/1 "2021-02-01T00:52:38Z")

</div>

Hey,  
So i have this challenge with my code. I want it to store the cursor values after mouse event is triggered.  
Here is my JS code trying to have two sets of cursor values stored;

```
<script>

function RHS(){
var e = window.event;

var posX1 = e.clientX;
var posY1 = e.clientY;

var posX2 = e.clientX;
var posY2 = e.clientY;

var A;
var B;
var RHS;

A = posX1 * posY1; //A(x,y)
B = posX2 * posY2; //B(x,y)
if (B >= A){
	RHS = B/A;
}
else {
RHS = A/B;
	}
	
alert(RHS);
}
</script>

```

Note: My code works but its not how I want. I Imagined clicking in the window twice would have different values for the different clientX; and clientY; sets as i clicked again.

---

<div class="post-metadata">

### Author: ![senseikaii](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@senseikaii](https://forum.kirupa.com/u/senseikaii)
#### Post date: [February 1, 2021, 1:58am UTC](https://forum.kirupa.com/t/i-want-to-get-two-seperate-instances-of-cursor-values-in-my-clientx-y-method-in-javascript/645929/2 "2021-02-01T01:58:02Z")

</div>

Hello,

If I understand what you are trying to achieve it’s to be able to store the position of the cursor but every time we click it’s the other client’s turn to store the pos.

What you can do is to use modulo (%) to know which client is clicking.  
You declare a variable `counter = 0` and every time you click, the counter is incremented. Then you check if the counter is even or odd.

I did this to demonstrate :

> **[Edit fiddle - JSFiddle - Code Playground](https://jsfiddle.net/1vmuz9n3/1/)**
>
> JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.

I Hope I understood your question and not off topic.

---

<div class="post-metadata">

### Author: ![Fejiro\_Eruotor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/fejiro_eruotor/32/13483_2.png) [@Fejiro\_Eruotor](https://forum.kirupa.com/u/Fejiro_Eruotor)
#### Post date: [February 1, 2021, 6:03pm UTC](https://forum.kirupa.com/t/i-want-to-get-two-seperate-instances-of-cursor-values-in-my-clientx-y-method-in-javascript/645929/3 "2021-02-01T18:03:43Z")

</div>

Thanks for the help, your modulo approach and if statement helped me get the solution 🙂 Now all I need to do is find how to make the values a global variable so i can access them throughout my script. Thanks again!

---

<div class="post-metadata">

### Author: ![Fejiro\_Eruotor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/fejiro_eruotor/32/13483_2.png) [@Fejiro\_Eruotor](https://forum.kirupa.com/u/Fejiro_Eruotor)
#### Post date: [February 1, 2021, 6:08pm UTC](https://forum.kirupa.com/t/i-want-to-get-two-seperate-instances-of-cursor-values-in-my-clientx-y-method-in-javascript/645929/4 "2021-02-01T18:08:19Z")

</div>

here is my app with transparent window in action now 🙂 ;

 ![screenshot](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/2X/4/4391fa3bd77a444816103581c3c42c5d12bf7764.png)  
PS: I made it Coral color so you can see the screen!
