Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!