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

232
Visualizações
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
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