Bonjour à tous, je désespère de ne pas trouver la solution. Dans mon précédent post que j'ai mis à résolu ce matin, je n'avais pas encore testé mon petit formulaire en ajoutant un bouton.
Il s'agit d'un formulaire avec dix textbox et un bouton submit
j'ai une fonction javascript qui me permet lorsque l'on appuie sur la touche entrée de passer à la textbox suivant (avec un focus)
Le problème est qu'après avoir ajouté le bouton ma fonction ne fonctionne plus.
J'ai rajouté une fonction qui désactive la touche entrée mais dès que l'on place le curseur dans une des textbox cela ne fonctionne plus
voici ce que j'ai fait :
Et dans le code-behind
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
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 <script language="javascript"> function key(){ if(window.event.keyCode == 13) { return; } } function trap(event,boxEnCours) { if((event.which && event.which == 13)||(event.keyCode && event.keyCode == 13)) { nbTmpTextBox = boxEnCours.charAt(3); document.onkeydown = key; if (nbTmpTextBox.length > 0) { nbTmpTextBox++; tmp = 'box'+ nbTmpTextBox++; document.getElementById(tmp).focus(); } } } function Autotab(boxSuivante,texte) { if (texte.length > 39) { document.getElementById(boxSuivante).focus(); } } </script> <form id="Form1" method="post" runat="server"> <table cellspacing="0" cellpadding="0"> <tr> <td> <span> 1.</span> <asp:TextBox ID="box1" MaxLength="40" Runat="server" /> </td> </tr> <tr> <td> <span> 2.</span> <asp:TextBox ID="box2" MaxLength="40" Runat="server" /> </td> </tr> <tr> <td> <span> 3.</span> <asp:TextBox ID="box3" MaxLength="40" Runat="server" /> </td> </tr> <tr> <td> <span> 4.</span> <asp:TextBox ID="box4" MaxLength="40" Runat="server" /> </td> </tr> <tr> <td> <span> 5.</span> <asp:TextBox ID="box5" MaxLength="40" Runat="server" /> </td> </tr> <tr> <td> <span> 6.</span> <asp:TextBox ID="box6" MaxLength="40" Runat="server" /> </td> </tr> <tr> <td> <span> 7.</span> <asp:TextBox ID="box7" MaxLength="40" Runat="server" /> </td> </tr> <tr> <td> <span> 8.</span> <asp:TextBox ID="box8" MaxLength="40" Runat="server" /> </td> </tr> <tr> <td> <span> 9.</span> <asp:TextBox ID="box9" MaxLength="40" Runat="server" /> </td> </tr> <tr> <td> <span> 10.</span> <asp:TextBox ID="box10" MaxLength="40" Runat="server" /> </td> </tr> <tr> <td> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button> </td> </tr> </table> </form>
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 private void Page_Load(object sender, System.EventArgs e) { this.box1.Attributes.Add("onkeypress","return trap(event,'box1');"); this.box2.Attributes.Add("onkeypress","return trap(event,'box2');"); this.box3.Attributes.Add("onkeypress","return trap(event,'box3');"); this.box4.Attributes.Add("onkeypress","return trap(event,'box4');"); this.box5.Attributes.Add("onkeypress","return trap(event,'box5');"); this.box6.Attributes.Add("onkeypress","return trap(event,'box6');"); this.box7.Attributes.Add("onkeypress","return trap(event,'box7');"); this.box8.Attributes.Add("onkeypress","return trap(event,'box8');"); this.box9.Attributes.Add("onkeypress","return trap(event,'box9');"); this.Button1.Attributes.Add("onkeydown","return key();"); this.box1.Attributes.Add("onkeyup","return Autotab('box2',document.getElementById('box1').value);"); this.box2.Attributes.Add("onkeyup","return Autotab('box3',document.getElementById('box2').value);"); this.box3.Attributes.Add("onkeyup","return Autotab('box4',document.getElementById('box3').value);"); this.box4.Attributes.Add("onkeyup","return Autotab('box5',document.getElementById('box4').value);"); this.box5.Attributes.Add("onkeyup","return Autotab('box6',document.getElementById('box5').value);"); this.box6.Attributes.Add("onkeyup","return Autotab('box7',document.getElementById('box6').value);"); this.box7.Attributes.Add("onkeyup","return Autotab('box8',document.getElementById('box7').value);"); this.box8.Attributes.Add("onkeyup","return Autotab('box9',document.getElementById('box8').value);"); this.box9.Attributes.Add("onkeyup","return Autotab('box10',document.getElementById('box9').value);"); }
Partager