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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change cursor in function

Status
Not open for further replies.

fknusername

Programmer
Aug 19, 2003
6
CA
I have a function that loops through a lot rows in a table. This take an awful lot of time so I'd like to at least change the cursor to 'wait' at the start of the function and change it back to 'default' at the end.

My function is called in the OnMouseDown event.

 
Wrap it in a try..finally block so it changes back even if a JavaScript error is encountered.
Code:
function OnMouseDown(){
  try{
    document.body.style.cursor='wait';

    // Do your work here

  }
  finally {
    document.body.style.cursor='auto';
  }

}

Adam
 
Thanks, but my problem is that it doesn't show the wait cursor. It I remove the <code>document.body.style.cursor='default'</code>
at the end, I get the wait cursor...

Some exemple code

Code:
<input type='submit' OnMouseDown="ShowWait(); DoFunction();"/>

function ShowWait(){
   document.body.style.cursor='wait';
}

function DoFunction {
    //long WHILE or FOR loop
    document.body.style.cursor='default';
}
 
my problem is that it doesn't show the wait cursor. It I remove the <code>document.body.style.cursor='default'</code>
at the end, I get the wait cursor...

Of course - you're telling the browser to show the wait cursor, and then immediately afterwards, you're telling it to show the default cursor, as you have no long delay at the moment.

Does it work if you have a long delay in place?

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
As mentionned in the code segment, there's a very long loop, but I didn't put the code as it wouldn't be relevant. It takes up to 10 seconds to execute.
 
Yep, looks like IE turns the pointer into a combination pointer/hourglass during long processes. You're probably not going to be able to override that. Could you just show an image of an hourglass on the page? Or maybe load the table in a hidden iframe, change the pointer of the parent page, and display the iframe when it's done? Or handle this on the server-side?

Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top