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

111
Visualizações
JavaScript button function result after page reloading

I have a login and register modal and these modals share one same attribute, so I wanted to create an onclick function for each of the modals' submit buttons to trigger errors in respective modals. I tried this code to see if the button can trigger for the modals to show,

function loginModal(){
            $('#modal-register').modal('show');      
   }
    
   document.getElementById("modal-login-btn").addEventListener("click", loginModal);

and it does, however it only works before the page reload, as when i click the submit button, the page will reload. I want the modal to show after the page reload. I also tried this but it doesn't work.

$(document).ready(function(){
        function loginModal(){
            if (count($errors) > 0){
                $(document).ready(function(){
                    $('#modal-login').modal('show');
                });
            }        
        }
    });
    
    document.getElementById("modal-login-btn").addEventListener("click", loginModal);

Does anyone have any idea how to make the function run after page reload?

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

0

You can use a GET value at the url of the page when the page reload:

  1. you can set the url in javascript at the moment of reload

for example

window.location.replace(window.location.href+"?reloaded=true");

  1. implement a function who detect if the url contains a reload GET value.

  2. if the GET value exist, show the modal directly.

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