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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<script>
var Choix = new Array("listeChoix1", "listeChoix2", "listeChoix3");
var relationChampChoix = new Array();
// structure : relationChampChoix["IdChamp"] = new Array("IdChampGauche", "IdListecorrespondante", "IdChampDroite")
relationChampChoix["ch1"]= new Array( null ,"listeChoix1", "ch2") ;
relationChampChoix["ch2"]= new Array( "ch1" ,"listeChoix2", "ch3") ;
relationChampChoix["ch3"]= new Array( "ch2" ,"listeChoix3", null) ;
var relationChoixChamp = new Array();
relationChoixChamp['listeChoix1']= 'ch1';
relationChoixChamp['listeChoix2']= 'ch2';
relationChoixChamp['listeChoix3']= 'ch3';
function touchePressee(champ, event)
{
var touche = event.keyCode;
/////////////////////
// Champs de Saisie//
/////////////////////
if( typeof(relationChampChoix[champ.id]) != 'undefined')
{
voisinsChamp= relationChampChoix[champ.id];
// Descente(/montée) dans la liste de Choix := flèche Bas/Haut
if((touche == 40 || touche == 38) && relationChampChoix[champ.id][1] != null)
{
afficherAideSaisieDe(champ);
}
// Champ de gauche
if (touche == 37 && event.shiftKey && relationChampChoix[champ.id][0] != null)
{
document.getElementById(relationChampChoix[champ.id][0]).focus();
}
// Champ de droite
if (touche == 39 && event.shiftKey && relationChampChoix[champ.id][2] != null)
{
document.getElementById(relationChampChoix[champ.id][2]).focus();
}
}
////////////////////
// Champs de Choix//
////////////////////
else if( typeof(relationChoixChamp[champ.id]) != 'undefined')
{
// Validation choix (Entrée)
if (touche == 13)
{
var champCible= document.getElementById(relationChoixChamp[champ.id]);
champCible.value=champ.value; //on récupère la valeur choisie et on la place dans le champ cible
champCible.focus();//on donne le focus sur le champ cible
effacerBloCompletude();
}
// retour au champ sans modif (<- ou -> ou Echap)
if ( (touche == 37 || touche == 39 || (touche == 27) ) && relationChoixChamp[champ.id] != null)
{
document.getElementById(relationChoixChamp[champ.id]).focus();
effacerBloCompletude();
}
}
}
/* affiche le bloc d'aide à la saisie et met le focus dans la liste des choix qu'il propose*/
function afficherAideSaisieDe(champ)
{
var blocAide = document.getElementById(relationChampChoix[champ.id][1]);
effacerBloCompletude();
blocAide.className= 'cadreVisible';
blocAide.focus();
for (var i=0; i<blocAide.options.length; i++)
if(blocAide.options[i].value == champ.value)
blocAide.selectedIndex = i ; //AFAIRE empecher déplacement supplémentaire du à l'appuie sur H/B
}
function effacerBloCompletude()
{
for(var a=0; a<Choix.length; a++)
document.getElementById(Choix[a]).className='cadreCache';
}
</script>
<style>
.champs> * { float: left ; padding : 5px; }
.cadreVisible { display : block; ; visibility : visible ; }
.cadreCache { display : none; visibility : hidden; ; }
/* AFFAIRE: épurer les styles suivants : */
input[type="button"]:hover
{
background:#999999 none repeat scroll 0%;
color:#FFFFFF;
}
input{
border:1px solid #AAAAAA;
}
input[type="button"]{
background:#FFFFFF none repeat scroll 0%;
color:#000000;
padding: 2px;
margin: 6px;
margin-left: 10px;
}
.blocSaisie { margin : 8px ; margin-left : 1px ; margin-right : 1px ; padding:0px}
</style>
</head>
<body>
<form onSubmit="javascript: return(false);">
<div class="champs">
<div class='blocSaisie'>
<input type="text" id="ch1" name="ch1" onkeydown="javascript:touchePressee(this,event);">
<div id="choixCh1">
<SELECT NAME="listeChoix1" id="listeChoix1" size="5" onkeydown="javascript:touchePressee(this,event);">
<OPTION VALUE="0" > la valeur 0 </option><OPTION VALUE="1" > la valeur 1 </option><OPTION VALUE="2" > la valeur 2 </option><OPTION VALUE="3" > la valeur 3 </option><OPTION VALUE="4" > la valeur 4 </option><OPTION VALUE="5" > la valeur 5 </option><OPTION VALUE="6" > la valeur 6 </option><OPTION VALUE="7" > la valeur 7 </option><OPTION VALUE="8" > la valeur 8 </option><OPTION VALUE="9" > la valeur 9 </option><OPTION VALUE="10" > la valeur 10 </option><OPTION VALUE="11" > la valeur 11 </option><OPTION VALUE="12" > la valeur 12 </option><OPTION VALUE="13" > la valeur 13 </option><OPTION VALUE="14" > la valeur 14 </option><OPTION VALUE="15" > la valeur 15 </option><OPTION VALUE="16" > la valeur 16 </option><OPTION VALUE="17" > la valeur 17 </option><OPTION VALUE="18" > la valeur 18 </option><OPTION VALUE="19" > la valeur 19 </option> </SELECT>
</div>
</div>
<div class='blocSaisie'>
<input type="text" id="ch2" name="ch2" onkeydown="javascript:touchePressee(this,event);">
<div id="choixCh2">
<SELECT NAME="listeChoix2" id="listeChoix2" size="3" onkeydown="javascript:touchePressee(this,event);">
<OPTION VALUE="Mr" > Mr </option>
<OPTION VALUE="MME"> Mme </option>
<OPTION VALUE="MLLE"> Mlle </option>
</SELECT>
</div>
</div>
<div class='blocSaisie'>
<input type="text" id="ch3" name="ch3" onkeydown="javascript:touchePressee(this,event);">
<div id="choixCh3">
<SELECT NAME="listeChoix3" id="listeChoix3" size="1" onkeydown="javascript:touchePressee(this,event);" >
<OPTION VALUE="A"> A </option>
<OPTION VALUE="B"> B </option>
<OPTION VALUE="C"> C </option>
<OPTION VALUE="D"> D </option>
<OPTION VALUE="E"> E </option>
<OPTION VALUE="F"> F </option>
</SELECT>
</div>
</div>
<input type="button" value="Valider !">
</div>
</form>
<script> effacerBloCompletude(); </script>
</body>
</html> |
Partager