0

I have a check box:

   <tr><td class="form-row" colspan="2" style="font-weight:bold; font-size:10px; color: #006699;"> <a href="javascript:void(0);"></a>
        <label> Display Value</label>
            <input type="checkbox" name="Display"  id="Display" />
    </td></tr>

Based on the onload function, i need to show/hide the checkbox completely.

        window.onload = function (e) {
        var dateOfToday = getCurrentDay();
        var presentDate = document.getElementById("presentDate");
       if (presentDate) {
            presentDate.value = dateOfToday;
        }
        var datetiMe = "<%= session.getAttribute("PresetValEndDate")%>";
        var setPVInput = formatDate(datetiMe);

        if (setPVInput > dateOfToday || setPVInput == dateOfToday){
            document.getElementById("myFieldset").disabled = false;
            //hidecheckbox

        }
        else(setPVInput < dateOfToday)
        {
            document.getElementById("myFieldset").disabled = true;
            //show checkbox

        }
    }

I tried the following but it didn't work.

 document.getElementById("Display").disabled = false;

Any help is appreciated. Thank you.

ace23
  • 142
  • 1
  • 16

2 Answers2

0

if you want to do it via javascript rather than CSS you can use:

var link = document.getElementById('Display');
link.style.display = 'none';//OR
link.style.visibility = 'hidden';
user1532647
  • 46
  • 1
  • 6
0

If you want to hide it you have to change the display. Change your code to:

if (setPVInput > dateOfToday || setPVInput == dateOfToday){
    document.getElementById("Display").style.display = "none";
}
else(setPVInput < dateOfToday)
{
    document.getElementById("Display").style.display = "block";
}

Which can be simplified to:

let checkbox = document.getElementById("Display");
checkbox.style.display = (setPVInput >= dateOfToday) ? "none" : "block";
T. Dirks
  • 3,566
  • 1
  • 19
  • 34
  • @ace23 if you have found a working solution in the answers, please select that answer as the accepted answer. https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – T. Dirks Oct 30 '18 at 15:00