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

229
Views
javascript continuous after form.submit() method called

When a Asp.Net aspx page on my site loads, a Javascript script runs a check on some condition, and if that condition is met, it should set an input element's value programmatically, and then submit the form, also programmatically, using form.submit(). With this, I am not using a click or submit event. The form should be processed backend and then the page reloaded with the correct data (and it does this correctly).

For some reason, this seems to work fine in FireFox, but it behaves differently in Chrome.

What is does in Firefox is that after the form.submit() the page reloads and my Javascript gets kicked off from the start (running the check again), as expected.

However, on Chrome, it seems that after the form.submit() call, the Javascript just continuous with the remaining Javascript code. I tried the form.requestSubmit(), but that didn't change it.

My code:

// check if someCondition is true, if so, a form field needs to be set prgrammatically and then the form submitted. If condition is false, just continue
if(someCondition){
   VerifyBeforeCheck();
}

DoTheNextThingIfConditionIsFalse(); //In Firefox, if VerifyBeforeCheck() is fired/ reached, this code never gets executed. In Chrome it will, but I don't want that.

// simple wrapper function, because SubmitMyForm gets called from different events and methods.
function VerifyBeforeCheck() {
    let newValue = sessionStorage.getItem("ItemFromSessionStorage");
    let fld = document.getElementById("formInputField"); // grabs an <input> field
    field.value = newValue; // used in backend
    SubmitMyForm();
}


function SubmitMyform(){
    let form = document.getElementById('myForm');
    form.submit();
}

Is this indeed unexpected behavior or am I missing something? I want the situation in Chrome to be as it is currently when I run it in Firefox: After the submit method, the form is submitted and then a page reload. If I need to use a preventDefault, how can I do this, without the event?

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!