0

I want to make a button (no style in particular) appear that will toggle this script on and off

var meta = document.createElement('meta');
meta.httpEquiv = "refresh";
meta.content = "30"; //Change the 30 to however many seconds you want to wait
document.getElementsByTagName('head')[0].appendChild(meta);
setTimeout(function(){
if(document.getElementById("next-btn")){
document.getElementById("next-btn").click()
}
var choice = Math.floor(Math.random()*100) < 100;      //Change the 93 to change percentage

if(choice){
document.querySelectorAll("input[value=Pass]")    [0].click();
}else{
document.querySelectorAll("input[value=Fail]")    [0].click();
}
}, 1000);
Ignazio
  • 10,504
  • 1
  • 14
  • 25
  • 2
    Please show what you have tried so far. There doesn't appear to be any attempt at any button event code here – charlietfl Feb 17 '16 at 14:53

1 Answers1

-1

Somthing like this will probly work but not sure what you use to trigger your event

<input type="button" onclick=OnOffAction()>

Javascript:

var isOn = true;

function OnOffAction() {
    if(isOn) isOn = false;
    else isOn = true;
}

var meta = document.createElement('meta');
meta.httpEquiv = "refresh";
meta.content = "30"; 
document.getElementsByTagName('head')[[0].appendChild(meta);
if(isOn) {
    setTimeout(function(){
    if(document.getElementById("next-btn")){
        document.getElementById("next-btn").click()
    }
    var choice = Math.floor(Math.random()*100) < 100;      
    if(choice){
        document.querySelectorAll("input[value=Pass]")    [0].click();
     }
    else{
    document.querySelectorAll("input[value=Fail]").   [0].click();
    }
    }, 1000);
}
Jaime02
  • 299
  • 7
  • 21
Alex C
  • 137
  • 8