Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda