Link to home
Start Free TrialLog in
Avatar of oldschwinn
oldschwinn

asked on

How Do I Exit a Javascript function when the User Clicks a Button/Link?

The following description will probably make a lot more sense if you look at this page while reading the description below:

http://www.stocklein.com/onix/test/auto_scroll.html

Here's the deal. I have a few scripts strung together that allows the user to use the Up and Down Arrow keys on the phone to control the scrolling of the content in the phone display. Those all work beautifully. No problems so far.

I recent added another script that "auto-scrolls" the content after a delay if the user doesn't scroll the content themselves. This is something that some cell phones currently do and I'm trying to mimic that functionality. If you go the page above and wait for four seconds the content should scroll to the bottom and then back up to the top. This also works beautifully.

Here comes the part I just cannot figure out. If at any time the user scrolls the content themselves (either up or down), the "auto-scrolling" should never happen. So for example, load this page wait four seconds until the auto-scrolling begines and then click either the Up or Down Arrow keys. At that point, the auto-scrolling should stop and the user should be in total control.

So it seems to me that all I really need to do is figure out how to bail out of the auto-scrolling function as soon as the user clicks either the Up or Down Arrow key.

Any thought?

P.S. All of the of the scripts are right on the page above and I think they are pretty easy to understand.
Avatar of eeBlueShadow
eeBlueShadow

it shouldn't be too hard, just have a variable called doautoscroll which is set to true when the document loads, which is set to false in the moveUp() and moveDown functions.

Then, check to see whether doautoscroll is true or false where you would normally start the auto scrolling.
I'm sure you can put these lines in without me needing to give you line numbers, but tell me if you need more help.

_Blue
Avatar of oldschwinn

ASKER

O.K., call me an idiot, but that's what I did indeed try, but I just couldn't get it to work. Then I thought maybe there was a much better solution like simply calling something like "exit=true" but I gues there is no such beast.

Anyhow, I would LOVE your help if you've got the time. I just need to get this darn thing working today!

Interested in helping more?
might be useful if you posed the code here
ASKER CERTIFIED SOLUTION
Avatar of lil_puffball
lil_puffball
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
lil_puffball,

Thanks so much for your help, that certainly worked! I've accepted your answer and awarded you all the points. If you're still interested in help, there is still one small problem. I'm thinking might we a simple fix with the order of the function calls or something? Again, I just cannot figure it out.

When the page loads, if you immediately (actually within four seconds before the autoscroll begins) click the Up Arrow the autoscrolled is "canceled" as it should be, but then after the four seconds are up, the content still scrolls down one "jump."
So it looks like the auto-scroll is getting canceled, but not until AFTER something is still being executed?

I'd love to be able to figure this out.

Again, thanks so much for your help!
Thanks for the points and the A. :)

Could you upload the new page so I can check it?
lil_puffball,

The latest and almost-greatest page is now here:

http://www.stocklein.com/onix/test/auto_scroll.html

Thanks soooooooooo much for all your help!
Oops, found the bug, here's the new autoscroll function:

function autoscroll(delay){
string="if(auto)pause("+delay+");";
setTimeout(string,delay);
}