How Do I Make A Button Only Available During A Certain Time Of Day In Html?
Solution 1:
Couple things wrong: 1) if you want it to be available from 6-8 your if statement should look like if (h >= 6 && h <= 8)
and 2) to remove the disabled attribute remove the parenthesis and .style
so that you have .disabled = false
.
HTML:
<inputid="bttHider"class="bttHider"type="submit" onclick="showHidden(); showbttHidden();" value="Add a new notice here." disabled>
JS:
var h = newDate().getHours();
if (h >= 6 && h <= 8) {
document.getElementById('bttHider').disabled=false;
}
Fiddle:
Solution 2:
Try something like this, without declaring datatype and with proper date object and your script within the body tag... Also, instead on piting onclick in your html, use an event listner in your javascript. If you read uo a little on event listners and javascript in general you will be writing a much better javascript...
<body><inputid="bttHider"class="bttHider"type="submit"onclick="showHidden(); showbttHidden();"value="Add a new
notice here."><script>var h = newDate().getHours();
var butn = document.getElementById('btttHider');
if (h <= 5 && h >=7) ){
btn.disabled=false;
} else {
btn.disabled=true;
}
</script></body>
Post a Comment for "How Do I Make A Button Only Available During A Certain Time Of Day In Html?"