0

Right now, I have to create printable documents. Now that I've got the formatting done, my client comes and says that if there are two Trustee names, he needs multiple Trustee signatures. This means I need to generate a second Signature page with the correct name on it. So I check the SecondTrustee variable and am trying to get the second page to show. Otherwise, just show one page.

Can someone show me what I'm doing wrong?

#trustee {
  width: 100%;
  padding: 50px 0;
  text-align: center;
  background-color: lightblue;
  margin-top: 20px;
}
<body>
  <script type="text/javascript">
    var second = "asdf";

    function checkSigs() {
      var x = document.getElementById("trustee");
      if (second === "") {
        x.style.display = "block";
      } else {
        x.style.display = "none";
      }
    }
    document.onload = checkSigs()
  </script>

  <p>First Trustee Page</p>

  <div id="trustee">
    <p>This is my Second Trustee Page.</p>
  </div>

</body>
isherwood
  • 58,414
  • 16
  • 114
  • 157

2 Answers2

0

Your javascript code is running before the div element is available so variable x is null. You need to move your script to the end of the html body.

teej
  • 135
  • 3
  • 11
0

You need to use window load not document load, or add your script at the end of the body.

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#trustee {
  width: 100%;
  padding: 50px 0;
  text-align: center;
  background-color: lightblue;
  margin-top: 20px;
}
</style>
</head>
<body>

  <script type="text/javascript">
    var second = "asdf";

    function checkSigs() {
      var x = document.getElementById("trustee");
      if (second === "") {
        x.style.display = "block";
      } else {
        x.style.display = "none";
      }
    }
    window.addEventListener('load', checkSigs)
  </script>
<p>First Trustee Page</p>

<div id="trustee">
  <p>This is my Second Trustee Page.</p>
</div>

</body>
</html>
Mina
  • 14,386
  • 3
  • 13
  • 26