سؤال

I want to show some message in span tag after my form gets submitted to the server. The problem is, the text disappears within seconds. Is it because the page is reloaded? Can anyone spot what is wrong with my function?

function placeOrder(form) {
    if (validateLength(1, 32, form["bannerMessage"], form["messageError"]) &&
     validateZipField(form["zipField"], form["zipError"]) &&
        validateEmptyFields(form["dateField"], form["dateError"]) &&
        validateEmptyFields(form["nameField"], form["nameError"]) &&
        validateEmptyFields(form["phoneField"], form["phoneError"]) &&
        validateEmptyFields(form["emailField"], form["emailError"])) {
        // Submit the order to the server
        form.submit();
       document.getElementById("submitSuccess").innerHTML = "Submitted successfully";


    } else {
        alert("I'm sorry but there is something wrong with the order information.");
    }
}
هل كانت مفيدة؟

المحلول

Exactly, you are sending the form to the server who will send back a complete page.

What you should do is have the new page contain the message that the form was successfully sent, or if there was a problem with the form (you do server-side validation, right?) -- give the details of the error.

For usability, it is important to make sure that you keep all of the form-fields you can. (E-Commerce fields are special, but keep everything else.)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top