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:

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.
Who is Participating?
BearishSun, the code is provided in the webpage.

oldschwinn, try this:

<base href="">
<title>Core Mobility | VisionCast</title>
<meta http-equiv="imagetoolbar" content="no">

<link rel="stylesheet" type="text/css" href="../mainNEW.css">
<script src="../scripts/main.js" language="javascript" type="text/javascript"></script>

<style type="text/css">
body {overflow:hidden}

<!--This is the stuff I added to do the autoscrolling. It's actually a combination of two separate scripts. The first two functions set a time delay so that the autoscrolling doesn't happen immediately. The second function then calls moveLayer which scrolls the content down. When the scrolling reaches the bottom, moveLayer then calls moveBack, and the content scrolls back to the top. At that point these scripts are done.-->
<script type="text/javascript">
function autoscroll(delay){
function pause(delay){

/*This script is made by bratta at
May be used freely as long as this msg is intact*/

if(document.layers){ // If Netscape 4
}else if(document.all){ // If IE4

function moveLayer(layer,ystop,step,speed){
var go;

if(!go) moveBack('content',0,-10,200)


function moveBack(layer,ystop,step,speed){
var go;

<script type="text/javascript">
var auto=true;

//specify speed of scroll (greater=faster)
var speed=20

if (iens6){
document.write('<div id="container" style="position:absolute;left:90;top:122;width:120px;height:140px;border:0px solid black;overflow:hidden;cursor:crosshair;z-index:2">')
document.write('<div id="content" style="position:absolute;left:90;top:122;width:120px;left:0;top:0;cursor:crosshair;z-index:2">')

<ilayer name="nscontainer" width="120" height="140" clip="0,0,120,140">
<layer name="nscontent" width="120" height="140" visibility="hidden">

<!-- scrolling content -->
<img src="../test/cry_for_help.gif" width="120" height="400" border="0">
<!-- end scrolling content -->


<script language="javascript">
if (iens6)


<body onload="button_init(); getcontent_height(); autoscroll(4000);">

<div id="phone"><img src="../images/phone.gif" width="282" height="754" border="0"></div>
<div id="display_frame"><img src="../images/display_frame.gif" width="120" height="160" border="0"></div>
<div id="arrows_up_down"><img src="../images/arrows_up_down.gif" width="5" height="15" border="0"></div>

<div id="soft_left"><a href="#" onclick="moveLayer('content',-360,-10,200)"><img src="../images/spacer.gif" hsrc="../images/buttons/soft_left.gif" width="48" height="24" border=0></a></div>

<div id="up"><a href="#" onMousedown="moveup();auto=false;" onMouseup="clearTimeout(moveupvar)" onMouseout="clearTimeout(moveupvar)"><img src="../images/spacer.gif" hsrc="../images/buttons/up.gif" width="24" height="24" border="0"></a></div>

<div id="down"><a href="#" onMousedown="movedown();auto=false;" onMouseup="clearTimeout(movedownvar)" onMouseout="clearTimeout(movedownvar)"><img src="../images/spacer.gif" hsrc="../images/buttons/down.gif" width="24" height="24" border="0"></a></div>

<script language="JavaScript1.2">
if (iens6){
var crossobj=document.getElementById? document.getElementById("content") : document.all.content
var contentheight=crossobj.offsetHeight
else if (ns4){
var crossobj=document.nscontainer.document.nscontent
var contentheight=crossobj.clip.height

var moveupvar=setTimeout("moveup()",20)
var movedownvar=setTimeout("movedown()",20)

function moveup(){
if (iens6&&parseInt(<=-(speed))"px"
else if (ns4&&<=0)

function movedown(){
if (iens6&&parseInt(>=(contentheight*(-1)+150))"px"
else if (ns4&&>=(contentheight*(-1)+150))

function getcontent_height(){
if (iens6)
else if (ns4)


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.

oldschwinnAuthor Commented:
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?
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

might be useful if you posed the code here
oldschwinnAuthor Commented:

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?
oldschwinnAuthor Commented:

The latest and almost-greatest page is now here:

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

function autoscroll(delay){
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.