Bonjour,
Dans le programme ci-dessous, je teste l'évènement onchange car je veux que mes inputs ne contiennent que certaines valeurs, dans le cas d'une valeur fausse, le message d'erreur doit s'afficher et le focus doit rester sur l'input en erreur.
Le test fonctionne bien avec l'évènement onkeyup mais lorsque onchange se met en action, le message d'erreur s'affiche bien mais le focus passe à l'autre input !!
Comment faire, merci.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <html> <head> <script language="javascript"> function FExit(zone) { var tt=zone.value.toUpperCase(); var ok=1; if ((tt!="C")&&(tt!="CA")&&(tt!="CM")&&(tt!="A")&&(tt!="M")&&(tt!="J")&&(tt!="")&&(tt!="D")&&(tt!="F")&&(tt!="FE")) {ok=0;} if (ok==0) { alert("Motif inconnu !"); return false; } } function FChgColor(zone) { zone.style.backgroundColor="#FDF3C1"; var tt=zone.value.toUpperCase(); if ((tt=="C")||(tt=="CA")||(tt=="CM")) { zone.style.backgroundColor="#FF33C1"; } } </script> <meta name="GENERATOR" content="Microsoft FrontPage 6.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Nouvelle page 1</title> </head> <body> <table> <tr> <td width="80" align="right"> <input type="text" name="20061107" value="J" size="2" maxlength="3" style="font-family: Tahoma; font-size: 10pt; background-color: #112233; text-transform:uppercase; text-align:center" onfocus="this.style.backgroundColor='red'" onblur="FChgColor(this)" onkeyup="FExit(this)" alt="C - Congés" onchange="FExit(this)"> </td> <td width="80" align="right"> <input type="text" name="20061107" value="J" size="2" maxlength="3" style="font-family: Tahoma; font-size: 10pt; background-color: #112233; text-transform:uppercase; text-align:center" onfocus="this.style.backgroundColor='red'" onblur="FChgColor(this)" onkeyup="FExit(this)" alt="C - Congés" onchange="FExit(this)"> </td> </tr> </table> </body> </html>
Partager