I'm struggling with a power button that is supposed to run two different cgi scripts when it is pressed.
I have some code like so (I've truncated the code between<main>
tags) :-
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body class="site">
<main>
<button href="#" class="buttonb" onclick="onoff()"><img class="on-button" src="images/power.png" alt="ON"></button>
</main>
<script>
var isOn=false;
function onoff()
{
if(isOn)
{
window.location.href="/cgi-bin/turnon.pl";
var isOn=true;
}else
{
window.location.href="/cgi-bin/turnoff.pl";
var isOn=false;
}
}
</script>
</body>
</html>
I have some css formatting things so it looks better too.
For some reason no matter what I do I can only get the else option to run on every button push. ie. it only runs the off script. The individual scripts do what is intended when run from the console.
Can someone shed some light on what is going on or maybe suggest another way of achieving the same thing? I'm a newbie to this stuff if that makes a difference
Thanks Steve