Problem with function to show div’s

Asked

Viewed 45 times

0

Good morning, I have a problem which is this: I want when the user clicks a button a div or multiple Divs will appear depending on the page they are on, but the function is only showing the first div, even using different id’s.

 <div class="w3-container w3-padding-32" id="about">
   <h3 class="w3-border-bottom w3-border-light-grey w3-padding-16">Sobre a escola</h3>
      <?php
          $sql_sobre = "SELECT sobre_augusto1 FROM campos";
          $sql_sobrequery = mysqli_query($conn, $sql_sobre) or die (mysqli_error($conn));
          $row = mysqli_fetch_row($sql_sobrequery);
          echo $row[0];
      ?><div id="edicao" hidden><code><b style="font-size:18px">Use &ltp&gt<i>exemplo de texto</i>&lt/p&gt quando quiser fazer um parágrafo.</b></code><form method="POST" action="confirmarEdicao.php"><textarea class="textboxEditar" name="edicaoSobreAugusto1"><?php echo $row[0]; ?></textarea> <input class="buttonEditar" type="submit" value="Confirmar"></form></div>
      <img src="planta.jpg" class="w3-image center">
      <?php
          $sql_sobre = "SELECT sobre_augusto2 FROM campos";
          $sql_sobrequery = mysqli_query($conn, $sql_sobre) or die (mysqli_error($conn));
          $row = mysqli_fetch_row($sql_sobrequery);
          echo $row[0];
      ?><div id="edicao1" hidden><code><b style="font-size:18px">Use &ltp&gt<i>exemplo de texto</i>&lt/p&gt quando quiser fazer um parágrafo.</b></code><form method="POST" action="confirmarEdicao.php"><textarea class="textboxEditar" name="edicaoSobreAugusto2"><?php echo $row[0]; ?></textarea> <input class="buttonEditar" type="submit" value="Confirmar"></form></div>
  </div>

The Divs I want to appear and disappear are the ones with 'id="edition..."'.

My javascript function is as follows:

function ativaredicao(){
    var x = document.getElementById("edicao");
    var y = document.getElementById("edicao1");
    if ((x.style.display === "none") || (y.style.display === "none"))  {
        x.style.display = "block";
        y.style.display = "block";
    } else {
        x.style.display = "none";
        y.style.display = "none";
    }
}
  • Here worked the two Ivds, changes the Hidden by style="display:None", but even with Hidden worked

  • For me it just keeps popping out the first

  • Is there an error in the Devtools Console? And to test it removes PHP and leaves only HTML and JS

  • has 2 errors but has nothing to do with this code. even taking out php I continue with the problem.

  • If the error is JS it for the execution of scripts, if it is something like (Not Found) has no problem

  • There is an error in JS but it is because it has a function in the same file, in which is the activated function(), which is not being used in this page, it matters?

  • Can interfere, checks whether a separate document works, only HTML and JS

  • Okay, I’ve separated the two functions into different files and it’s working, thank you for your time!

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.