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

283
Views
Button to reload page does not reload page

I was trying to press a button to reload the page but it doesn't work and I don't know why

I'm using handlebars, so in theory all this code down here is inside a <body>

It sends the "POST" and everything okay, the only thing that does not run is the script

As a little relevant information, I am using Bootstrap 5.

<script>
const reload = document.getElementById('reload');

reload.addEventListener('click', _ => { 
    window.location.reload();
});
</script>

<div class="Things with little reference">

. . .

   <form action="/dashboard/" method="POST">
      <div class="form-group">
         <button id="reload" class="btn btn-success">ye!</button>
      </div>
   </form>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

The default type of button is "submit" which will submit the form.

for this case, you should change the button type to "button" or use preventDefault to stop the default behavior of the button clicked.

change the button type to "button"

  <button type="button" id="reload" class="btn btn-success">ye!</button>

or use preventDefault

reload.addEventListener('click', e => { 
    e.preventDefault()
    window.location.reload();
});

about 4 years ago · Juan Pablo Isaza Report

0

Instead of using JS you can directly specify it in button.

<button onClick="window.location.reload();" class="btn btn-success" >ye!</button>
about 4 years ago · Juan Pablo Isaza Report

0

After submiting the form You can call the method for reloading from onSubmit event.

<button type="button" onClick="onSubmit()">Close</button>
<script>
function refreshPage(){
    window.location.reload();
} 
onSubmit()
{
   /*Here you can add your code for submit event*/
   this.refreshPage();
}
</script>
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!