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

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;


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;

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.


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 :

I Hope I understood your question and not off topic.


Thanks for the help, your modulo approach and if statement helped me get the solution :slight_smile: 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!

here is my app with transparent window in action now :slight_smile: ;

PS: I made it Coral color so you can see the screen!