Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set the location of the cursor 1

Status
Not open for further replies.

sgprice78

IS-IT--Management
Jun 20, 2001
15
CA
Does anybody know how to set the X and Y coordinates of the cursor on the screen. I have seen plenty of example code of how to GET the cursor's current coordinates, but I have to be able to SET the cursor's location through Javascript code.

I am working on a web application that contains a table. As the user moves the mouse over each row of the table, the row is highlighted. Most of the cells in the table can be clicked on and will pop up a sub-menu that allows the user to view/edit the contents of the cell.

The problem is: After the user is done viewing/editting the information in the sub-menu and the sub-menu closes, his/her cursor is now most likely hovering over a different row. The users are forgetting which row it was that they just looked at. They want the mouse to move back to the row that they were on before they clicked to open the sub-menu.

I know this sounds like a stupid complaint, but it is now a required feature of my applicaiton.

Thanks in advance,
Scott
 
For starters it's not a stupid complaint... it's a valid user interface issue.

However the functionality for getting the cursor position actually gets the cursor position at the time the particular event was fired. The clientX and clientY values actually belong the the event, not the cursor. These properties are read only unless the event is one you have created using document.createEventObject()

Even if they were read/write, events are not retroactive. When you call document.forms[0].button1.click() the browser doesn't physically move the cursor to the button and simulate a left-click, it just calls the event handler. So writing to the clientX and clientY would be ineffectual.

So no, there is no means that I can see of repositioning the user's cursor with JavaScript. I can see why... Imagine the fun porn sites (I'm told that porn is available on the internet) would have with resetting the mouse position on the document.onmouseout event.

So perhaps there is some other way of redirecting your users to the correct row. Maybe as well as changing the colour on the mouseover and mouseout events, you could set it to a different colour or shade when the user clicks on the cell... and then leave it that colour until a few seconds after the user closes the popup.
 
Thanks you for your quick response dwarfthrower.

I didn't consider the dangers of JavaScript being able to move the mouse ;)

Thanks for the great suggestion, I think that our user group will be happy with that functionality.

Scott

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top