2

I'm using this code to start a log file :

function startTail(str) {
if (str== "stop") {
stopTail();
} else {
t= setTimeout("getLog()",1000);
}
}

This is called using :

<button id="start" onclick="getLog('start');">

and stopped using :

<button id="stop" onclick="getLog('stop');">

Is there anyway I can change this to one button that will toggle start / stop ?

1

2 Answers 2

1

Try:

<button id="start" value="Toggle Log" onclick="getLog('start', this);">

function startTail(str, element) {
    if (str == "stop") {
        stopTail();
        element.setAttribute('onclick', "getLog('start', this);");
    } else {
        element.setAttribute('onclick', "getLog('stop', this);");
    }
}   
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this starts the log, but seems to stop it straight way. This is the log script I'm using : commavee.com/2007/04/13/ajax-logfile-tailer-viewer
Thanks, I had to update another function that was calling startTail() to startTail(str, element) !
0

You could try this

var flag = false;
function startTail() {
 if (flag)
  {
    stopTail();
    document.getElementById('start').value = "Start";
    flag = false;
  }
 else 
  {
    t= setTimeout("getLog()",1000);
    flag = true;
    document.getElementById('start').value = "Stop";
  }
}

<button id="start" onclick="startTail();" value="Start">

1 Comment

This seems to do the same as the above. starts but then stops.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.