var selIndex = 0; var nbMatch = 0; var content = ''; var old = ''; function Clearchamp2() { document.getElementById('champ2').value = ''; document.getElementById('Listechamp2').style.display= 'none'; document.getElementById('Listechamp2').innerHTML=''; } function Clearchamp3() { document.getElementById('champ3').value = ''; document.getElementById('Listechamp3').style.display= 'none'; document.getElementById('Listechamp3').innerHTML=''; } function Clearchamp1() { document.getElementById('champ1').value = ''; document.getElementById('Listechamp1').style.display= 'none'; document.getElementById('Listechamp1').innerHTML=''; } function Clearchamp0() { document.getElementById('champ0').value = ''; document.getElementById('Listechamp0').style.display= 'none'; document.getElementById('Listechamp0').innerHTML=''; } function Focuschamp1() { Clearchamp2(); Clearchamp3(); } function Focuschamp2() { Clearchamp3(); if (document.getElementById('champ1').value == '') { alert("Vous devez entrer un champ !"); Clearchamp2(); document.getElementById('champ1').focus(); } } function Focuschamp3() { if (document.getElementById('champ2').value == '') { alert("Vous devez entrer un champ !"); Clearchamp2(); document.getElementById('champ2').focus(); } if (document.getElementById('champ1').value == '') { alert("Vous devez entrer un champ !"); Clearchamp2(); document.getElementById('champ1').focus(); } } function Focuschamp0() { } function valider(){ if(document.getElementById('champ1').value.length >0) { nbMatch = 0; for (var i=0; i < champ[1].length; i++) { if ( champ[1][i]==document.getElementById('champ1').value && ( (champ[2][i]==document.getElementById('champ2').value) || (document.getElementById('champ2').value =='') ) ) nbMatch++; } if (nbMatch>0) { return true; } else { alert("Les noms saisis sont invalides."); Clearchamp1champ2(); document.getElementById('champ1').focus(); return false; } } else { alert("Saisissez au moins un champ "); return false; } } function valider2(){ if(document.getElementById('champ0').value.length >0) { nbMatch = 0; for (var i=0; i < champ[0].length; i++) { if ( champ[0][i]==document.getElementById('champ0').value) nbMatch++; } if (nbMatch>0) { return true; } else { alert("Le champ saisi est invalide."); Clearchamp0(); document.getElementById('champ0').focus(); refreshList(); return false; } } else { alert("Saisissez un"); document.getElementById('champ0').focus(); return false; } } function validermodif(){ if(document.getElementById('champ1').value.length >0 && document.getElementById('champ2').value.length >0) { nbMatch = 0; for (var i=0; i < champ[1].length; i++) { if ( champ[1][i]==document.getElementById('champ1').value && ( (champ[2][i]==document.getElementById('champ2').value) || (document.getElementById('champ2').value =='') ) ) nbMatch++; } if (nbMatch>0) { return true; } else { alert("Les noms saisis sont invalides."); Clearchamp1champ2(); document.getElementById('champ1').focus(); return false; } } else { alert("Saisissez tous les champs "); return false; } } function validerinsert(){ if(document.getElementById('champ1').value.length >0 && document.getElementById('champ2').value.length >0) { newvalu=document.getElementById('champ1').value.substr(0,1); newvalu=newvalu.toUpperCase(); nextvalu=document.getElementById('champ1').value.substr(1,document.getElementById('champ1').value.length-1); newvalu=newvalu + nextvalu; document.getElementById('champ1').value = newvalu; return true; } else { alert("Saisissez tous les champs "); return false; } } function validerfamille(){ if(document.getElementById('champ3').value.length >0) { return true; } else { alert("Saisissez le champ "); return false; } } function fillInput(i) { champencours=document.activeElement.id; Listeencours='Liste'+champencours; numchamp=champencours.substring(5,champencours.length); document.getElementById(champencours).value = champ[numchamp][i]; document.getElementById(Listeencours).style.display= 'none'; document.getElementById(champencours).focus(); } function refreshList() { champencours=document.activeElement.id; Listeencours='Liste'+champencours; numchamp=champencours.substring(5,champencours.length); /* examen des cas */ if ( (numchamp == 2) || (numchamp == 3)) { /* champs dépendants */ condition1 = (document.getElementById(champencours).value.length > 0); condition1 = condition1 && (document.getElementById(champencours).value != old); if (condition1) old=document.getElementById(champencours).value; condition1= (old) || condition1; if (condition1) { old=document.getElementById(champencours).value; document.getElementById(Listeencours).innerHTML = ''; nbMatch = 0; content=''; for (var i=0; i < champ[numchamp].length; i++) { /*Recherche des champ[][] compatibles */ /* condition de compatibilité des contenus */ condition = (champ[numchamp][i].slice(0, document.getElementById(champencours).value.length).toUpperCase() == document.getElementById(champencours).value.toUpperCase() ); condition = condition && champ[1][i] == document.getElementById('champ1').value; if (numchamp == 3) condition = condition && champ[2][i] == document.getElementById('champ2').value; if (condition) { nbMatch++; content += '
' + champ[numchamp][i] + '
'; } /* fin if (condition) */ } /* fin boucle recherche */ if (nbMatch) { /* actualisation liste déroulante */ document.getElementById(Listeencours).innerHTML = content; document.getElementById(Listeencours).style.height = (Math.min(5, nbMatch)) + 'em'; document.getElementById(Listeencours).style.display = 'block'; selIndex=0; } else document.getElementById(Listeencours).style.display = 'none'; /* fin actualisation */ } /* fin if (conditon1) */ } else { /* Traitement des champs indépendants */ condition1 = (document.getElementById(champencours).value.length > 0); condition1 = condition1 && (document.getElementById(champencours).value != old); if (condition1) { old=document.getElementById(champencours).value; document.getElementById(Listeencours).innerHTML = ''; nbMatch = 0; content=''; for (var i=0; i < champ[numchamp].length; i++) { /*Recherche des champ[][] compatibles */ Allready = 0; /* condition de compatibilité des contenus */ condition = (champ[numchamp][i].slice(0, document.getElementById(champencours).value.length).toUpperCase() == document.getElementById(champencours).value.toUpperCase() ); if (condition) { /* condition supplémentaire: le champ[][] ne doit pas être déjà listé */ for (var j=0; j < i; j++) { if (i==0) break; if (champ[numchamp][i] == champ[numchamp][j]) Allready = 1; } if (Allready == 0) { nbMatch++; content += '
' + champ[numchamp][i] + '
'; } } /* fin if (condition) */ } /* fin boucle recherche */ if (nbMatch) { /* actualisation liste déroulante */ document.getElementById(Listeencours).innerHTML = content; document.getElementById(Listeencours).style.height = (Math.min(5, nbMatch)) + 'em'; document.getElementById(Listeencours).style.display = 'block'; selIndex=0; } else document.getElementById(Listeencours).style.display = 'none'; /* fin actualisation */ } /* fin if (conditon1) */ } /* fin examen des cas */ } /* Fin procédure */ function moveSelection() { if (event.keyCode == 40) { if (selIndex > 0 && selIndex < nbMatch) { document.getElementById(selIndex).style.backgroundColor = 'white'; document.getElementById(selIndex).style.color = 'black'; } if (selIndex < nbMatch) { selIndex++; document.getElementById(selIndex).style.backgroundColor = 'darkblue'; document.getElementById(selIndex).style.color = 'white'; document.getElementById(selIndex).focus(); } return false; } else if (event.keyCode == 38) { if (selIndex > 1) { document.getElementById(selIndex).style.backgroundColor = 'white'; document.getElementById(selIndex).style.color = 'black'; } if (selIndex > 1 && selIndex <= nbMatch) { selIndex--; document.getElementById(selIndex).style.backgroundColor = 'darkblue'; document.getElementById(selIndex).style.color = 'white'; } return false; } return getEnterKey(); } function getEnterKey() { champencours=document.activeElement.id; Listeencours='Liste'+champencours; numchamp=champencours.substring(5,champencours.length); if (event.keyCode == 13) { if (selIndex > 0) { document.getElementById(champencours).value = document.getElementById(selIndex).innerText; champChoisi[numchamp]=document.getElementById(champencours).value; document.getElementById(Listeencours).style.display = 'none'; old=document.getElementById(selIndex).innerText; document.getElementById(Listeencours).innerHTML = ''; if (numchamp == 1) { document.getElementById('champ2').value = ''; document.getElementById('champ2').focus(); } if (numchamp == 2) { document.getElementById('champ3').focus(); } if (numchamp == 3) { document.getElementById('submit').focus(); } } return false; } else return true; } -->