Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
how to execute the javascript functionalities from php file

I work on php and javascript. Now I want to call the javascript functionalities in my php code but it is now working. the code of php that execute the javascript code is

echo '<script type="text/javascript">
        alert( document.getElementById("popup"));
        document.getElementById("popup").style.display = "block";
        document.getElementById("popup").classList.toggle("active");
</script>';

but the alert gives a null value and does not execute the code of html. the code of html is

    <div class="popup" id="popup">
        <div class="overlay"></div>
        <div class="content">
            <!-- <div class="close-btn" onclick="closePopup()">&times;</div> -->
            <div class="row">
                <div  class="col-lg-12 col-md-9  col-sm-12">
                    <img width="200" height="200" src="https://cdn.dribbble.com/users/2469324/screenshots/6538803/comp_3.gif">
                    <h2 id="errorHead">fields are required</h2>
                    <p id="errorMessage">
                        All fields are required. fill all fields
                    </p>
                    <button style="background-color: darkgreen; width: 130px; margin-top: 5%;" class="btn btn-success radiusChange backgroundChange" onclick="closePopup()"> Close</button>
                </div>
            </div>
        </div>
    </div>

how I execute this code, basically it is the popup that I want to run. please give the way to solve this problem.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Call JS Code</title>
    <?php
    echo '<script type="text/javascript">
    alert("Execute Javascript Code");
    </script>';
    ?>
  </head>
  <body>
  </body>
</html>

about 4 years ago · Juan Pablo Isaza Relatório

0

You have to wait for the document to be completely loaded before accessing its nodes.

May you try echoing the following ? You should get the #errorMessage content, ie you are now able to access the popup node and do your stuff

<script type="text/javascript">
  window.onload = () => {
    alert(document.getElementById("popup").querySelector("#errorMessage").innerText);
    //you can deal with the popup node :)
  }; 
</script>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda