0

I have a list of checkboxes that I want to display based on current time when user clicks a button.

JS:

var hour = (new Date()).getHours();
showMed('A', hour == 19);
showMed('B', hour == 19);
showMed('C', hour == 13);

function showMed(med, show) {
document.getElementById('med' + med).style.display = show ? '' : 'none';
}

HTML

<div class="inner" id=text><button onClick="showMed()">Check</button></div>
<form>
<div id='medA'>
<input type="checkbox" name="Med A" value="A">Medication A
</div>
<div id='medB'>
<input type="checkbox" name="Med B" value="B">Medication B
</div>
<div id='medC'>
<input type="checkbox" name="Med C" value="C">Medication C
</div>
</form>

I want the user to click the button and it will display the checkboxes based on the current time. But at the moment I can't seem to call the function

1
  • I think you are going to need to add some more description. I can't really tell what exactly you're trying to do. Commented Jul 28, 2016 at 5:24

1 Answer 1

1

I guess you should try this:

JS:

function myFunction(){
   var hour = (new Date()).getHours();
   showMed('A', hour == 19);
   showMed('B', hour == 19);
   showMed('C', hour == 13);
}

function showMed(med, show) {
   document.getElementById('med' + med).style.display = show ? '' : 'none';
}

HTML

 <div class="inner" id=text><button onClick="myFunction()">Check</button></div>
<form>
<div id='medA'>
<input type="checkbox" name="Med A" value="A">Medication A
</div>
<div id='medB'>
<input type="checkbox" name="Med B" value="B">Medication B
</div>
<div id='medC'>
<input type="checkbox" name="Med C" value="C">Medication C
</div>
</form>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.