1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| <script type="text/javascript">
var checked = new Object();
checked["nom"] = 0;
checked["prenom"] = 0;
checked["password"] = 0;
checked["repassword"] = 0;
checked["email"] = 0;
checked["url"] = 0;
function getXhr(){
var xhr = null;
if(window.XMLHttpRequest) // Firefox et autres
xhr = new XMLHttpRequest();
else if(window.ActiveXObject){ // Internet Explorer
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else { // XMLHttpRequest non supporté par le navigateur
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
xhr = false;
}
return xhr;
}
function Check(type, input, value){
content = document.getElementById("input-"+input); //zone d'affichage
var XhrObj = getXhr();
XhrObj.open("POST", "AjaxTemplates/FormuCheck.php");
XhrObj.onreadystatechange = function(){
if (XhrObj.readyState == 4 && XhrObj.status == 200) {
if (XhrObj.responseText == 'ok'){
// Resultat Ok
content.innerHTML='<img src="img/bibliotheque/valid.png" alt="Valide" />';
checked[input] = 1;
}else{
// Erreur
content.innerHTML='<img src="img/bibliotheque/unvalid.png" alt="Invalide" />';
checked[input] = 0;
}
}
}
XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
if(type == "repassword"){
XhrObj.send(type+'='+value+"&password="+document.forms["ajaxform"].elements["password"].value);
}else if(type == "reemail"){
XhrObj.send(type+'='+value+"&email="+document.forms["ajaxform"].elements["email"].value);
}else{
XhrObj.send(type+'='+value);
}
}
function testChamps(envoi) {
Check('text', 'nom', document.forms["ajaxform"].elements["nom"].value);
Check('text', 'prenom', document.forms["ajaxform"].elements["prenom"].value);
Check('password', 'password', document.forms["ajaxform"].elements["password"].value);
Check('repassword', 'repassword', document.forms["ajaxform"].elements["repassword"].value);
Check('email', 'email', document.forms["ajaxform"].elements["email"].value);
Check('url', 'url', document.forms["ajaxform"].elements["url"].value);
if(checked["nom"] == 0 || checked["prenom"] == 0 || checked["password"] == 0 || checked["repassword"] == 0 || checked["email"] == 0 || checked["url"] == 0){
document.getElementById("incomplete").innerHTML='Les champs ont été mal remplis.<br/><br/>';
return false;
}
return true;
}
</script> |
Partager