Created
December 14, 2018 12:33
-
-
Save mphuget/73c1da91afe9a6de80e5b5162ed38962 to your computer and use it in GitHub Desktop.
JavaScript + validation formulaire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title> Mon formulaire </title> | |
<script> | |
function validateEntries() { | |
nom = document.getElementById("nom").value; | |
prenom = document.getElementById("prenom").value; | |
email = document.getElementById("email").value; | |
console.log(nom); | |
console.log(prenom); | |
console.log(email); | |
if (nom == "" && prenom == "" && email == "") { | |
window.alert("Problem"); | |
return false; | |
} | |
else { | |
sessionStorage.setItem("nom", nom); | |
sessionStorage.setItem("prenom", prenom); | |
sessionStorage.setItem("email", email); | |
sessionStorage.setItem("users", JSON.stringify([1, 2, 3])); | |
return true; | |
} | |
} | |
function validateForm() { | |
nom = document.getElementById("nom").value; | |
prenom = document.getElementById("prenom").value; | |
email = document.getElementById("email").value; | |
if (nom !== "" && prenom !== "" && email !== "") { | |
document.getElementById("submit").disabled = false; | |
} | |
} | |
function modifyButton() { | |
document.getElementById("submit").disabled = true; | |
} | |
</script> | |
</head> | |
<body onload="modifyButton()"> | |
<form onsubmit="return validateEntries()"> | |
Nom:<br/> | |
<input type="text" name="nom" id="nom" placeholder="Entrez votre nom" onblur="validateForm()"><br/> | |
Prénom:<br/> | |
<input type="text" name="prenom" id="prenom" placeholder="Entrez votre prénom" onblur="validateForm()"><br/> | |
Email:<br/> | |
<input type="email" name="email" id="email" placeholder="Entrez votre email" onblur="validateForm()"><br/> | |
<br/> | |
<br/> | |
<input type="submit" id="submit" value="Création"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment