I have a local webpage on a stand alone machine for use as a Bingo program. On my button to call the balls, I have placed a timer to deactivate the button for three seconds so as to eliminate double clicks from calling two balls together. I have the timer as a Javascript function that is called on the onclick of the ball calling button. This works fine.
I now have a situation where for a special speed round game, I have to turn this off for the duration of this game. I have placed the timer function into an if else if statement that works, but it only works once. If I start with the on radio button selected, I can turn it off, but not back on again without doing a page refresh which wipes out the current game. The same goes for if I start with the off radio button selected.
This is curious as I have another radio button setting that allows for manual changing of the table cell background color that uses an if else if statement and it allows me to change this setting back and forth as many times as I would want without a page refresh.
Here is the code for the the timer deactivating function:
function threesectimeronoff()
{
if(document.getElementById('timeron').checked)
{
$('#aaa').click(function() {
var aaa = $(this);
aaa.prop('disabled', true);
setTimeout(function() {
aaa.prop('disabled', false);
}, 3000);
});
}
else if(document.getElementById('timeroff').checked) {
$('#aaa').click(function() {
var aaa = $(this);
aaa.prop('disabled', true);
setTimeout(function() {
aaa.prop('disabled', false);
}, 0000);
});
}
}
Two radio buttons on the bottom of the page have id's of timeron and timeroff which is checked by the if else statement.
Although one would not be turning these on and off in the middle of a game, I would like to have this work properly in case one of these radio buttons were to be selected by accident. Also, I would like to learn why one if else would work many times, when another will only work once...
Thanks, Stan...
basic sample HTML page code added:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
</HEAD>
<script type='text/javascript'
src='jquery-1.8.3.js'></script>
<SCRIPT LANGUAGE="Javascript">
function threesectimer()
{
if(document.getElementById('timeron').checked)
{
$('#aaa').click(function() {
var aaa = $(this);
aaa.prop('disabled', true);
setTimeout(function() {
aaa.prop('disabled', false);
}, 3000);
});
}
else if(document.getElementById('timeroff').checked) {
$('#aaa').click(function() {
var aaa = $(this);
aaa.prop('disabled', true);
setTimeout(function() {
aaa.prop('disabled', false);
}, 0000);
});
}
}
</SCRIPT>
<BODY STYLE="background-color: yellow" onload="LoadImages();ResetBoard();myBallsLeft();">
<FORM NAME="bingo">
<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" STYLE="background-color: white; border: 2px
solid #FF3399 ridge">
<TR>
<TD COLSPAN="2">
</td>
</tr>
<TR HEIGHT="20" BGCOLOR="YELLOW"><TD width="45%"><CENTER>
<INPUT TYPE="BUTTON" id="aaa" style="font-size:18px" VALUE="CALL NEXT BALL"
ONCLICK="threesectimer();"> <INPUT TYPE="TEXT"
style="color:blue;font-size:22px;text-align:center;" SIZE="3" NAME="output" READONLY>
<DIV>
<BIG><BIG>Timer
<form name="timeronoff">
<input type="radio" name="group2" id = "timeron" value="on" onchange="threesectimer();" checked>
ON
<input type="radio" name="group2" id = "timeroff" value="off" onchange="threesectimer();"> OFF
</big></big>
</form>
</div>
</div>
</center>
</BODY>
</HTML>
Here is the JSFIDDLE