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

265
Views
js onbeforeunload I want to submit the form after page refresh or close, but failed

I want to submit my form data to database when user refresh or close the window. I tried this, but it didn't work. The p demo1 will change to No when refresh or close. But will change to Yes after refresh or close. But the sumbit part is not trigger. I tried this two method, both of them didn't work document.getElementById("all_questions").submit(); $('#save').click(); It can work if I click the submit button, use Django as framework

<script>
    window.onbeforeunload = function(e){
    document.getElementById("demo1").innerHTML="No";
    document.getElementById("all_questions").submit();
    $('#save').click();
  }
</script>

<form method = "POST"  name = "answer_question" id="all_questions">
<p id="demo1">Yes</p>
data
<div class="save-item1"><button class="save-button" type="submit" id="save" name="Complete">Save</button></div>
</form>

about 4 years ago · Juan Pablo Isaza
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!