Reputation: 933
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 ?
Upvotes: 2
Views: 1724
Reputation: 12683
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);");
}
}
Upvotes: 1
Reputation: 19591
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">
Upvotes: 0