-1

after checking all the functions and after clicking on submit button the browser should be turning into submitted.html but that does not happened and i don't know why? here is my code

<form method="get"   onsubmit="return !!(checkForEmail() & checkForBlank()  
&checkForGsm())"    action="submitted.html">

checkForBlank function

function checkForBlank() {
        var nom = document.getElementById("fname").value;
        var prenom = document.getElementById("lname").value;
        var errorMessage="";

        if (nom == "") {
            errorMessage += "Le champ nom est obligatoire.";
            document.getElementById("lname").style.borderColor="red";
        }

        if (prenom == "") {
            errorMessage += "\nLe Champ prenom est obligatoire.";
            document.getElementById("fname").style.borderColor="red";
        }

        if (errorMessage != "") {
            alert(errorMessage);
            return false;
        }
    }

the others are similar.

1 Answers1

1

You are missing to return true; in case of success;

function checkForEmail() {
  return true;
}

function checkForGsm() {
  return true;
}

function checkForBlank() {
  var nom = document.getElementById("fname").value;
  var prenom = document.getElementById("lname").value;
  var errorMessage = "";

  if (nom == "") {
    errorMessage += "Le champ nom est obligatoire.";
    document.getElementById("lname").style.borderColor = "red";
  }

  if (prenom == "") {
    errorMessage += "\nLe Champ prenom est obligatoire.";
    document.getElementById("fname").style.borderColor = "red";
  }

  if (errorMessage != "") {
    alert(errorMessage);
    return false;
  }
  else{return true;}
}
<form method="get" onsubmit="return !!(checkForEmail() & checkForBlank() & checkForGsm())" action="submitted.html">
  <input type="text" name="fname" id="fname"><br/>
  <input type="text" name="lname" id="lname"><br/>
  <input type="submit" value="Submit" id="start"><br>
</form>
ElasticCode
  • 7,311
  • 2
  • 34
  • 45