Non :calim2:
Relis mieux ce qui a été dit (et répété) ...
A+
Version imprimable
Correction effectuée ?
:calim2:Code:
1
2
3
4
5
6 <div id='tranche' style='display:inline'> <select name='tranche' onchange='change2()'> ... <div id='groupement' style='display:inline'> <select name='groupement'>
ERE
EDIT: grillé ! ;)
----
ok, mais je croyais qu'il faut juste elever l'ID de des balises select qui été identique à l'ID des DIV ....
bon bein maintenant je vais modifier les names des balises select et on verra...
les amis veuillez excuser ma précipitation ;)
j'ai modifié et ça n'a rien donné :cry:
voici le form1.jsp aprés modif:
Code:
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 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import="java.util.Vector,java.util.Enumeration,GC.bean.Bien, GC.bean.Projet,GC.bean.Tranche,GC.bean.Groupement,GC.dao.GroupementDAO, GC.dao.ProjetDAO,java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <script type='text/javascript'> 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; } /** * Méthode qui sera appelée sur le click du bouton */ function change() { //Si c'est AUCUN qui est sélectionné, il faut réinitialiser //les 2 autres combos et quitter var sel = document.getElementById('projet'); if (sel.options[sel.selectedIndex].value == -1) { document.getElementById('tranche').options.length=0; document.getElementById('groupement').options.length=0; return; } var xhr = getXhr(); // On défini ce qu'on va faire quand on aura la réponse xhr.onreadystatechange = function() { //attendons dque le requete soit finie... if(xhr.readyState == 4 && xhr.status == 200){ //alert(xhr.responseText); var rst = xhr.responseXML; var items=rst.getElementsByTagName('element'); document.getElementById('tranche').options.length=0; //penser à réinitialiser aussi id_ref document.getElementById('groupement').options.length=0; for(var i=0;i<items.length;i++) { var myOption = new Option(items[i].getElementsByTagName('option')[0].firstChild.nodeValue,items[i].getElementsByTagName('valeur')[0].firstChild.nodeValue,false,true) document.getElementById('tranche').options[i]=myOption; } //mise à jour de id_ref pour le 1er prenom affiché (sinon incohérence //au niveau de l'affichage) change2(); } } // Ici on va voir comment faire du post xhr.open("POST","cmbtranche22.jsp",true); // ne pas oublier ça pour le post xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // ne pas oublier de poster les arguments // ici, l'id de l'auteur sel = document.getElementById('projet'); idprojet = sel.options[sel.selectedIndex].value; xhr.send("idProjet="+idprojet); } function change2() { //si un seul prenom... if (document.getElementById('prenom').options.length==1) { //on vide la derniere combo document.getElementById('groupement').options.length=0; //on quitte return; } var xhr = getXhr(); // On défini ce qu'on va faire quand on aura la réponse xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200){ // alert(xhr.responseText); var rst = xhr.responseXML; var items=rst.getElementsByTagName('element'); document.getElementById('groupement').options.length=0; for(var i=0;i<items.length;i++) { var myOption = new Option(items[i].getElementsByTagName('option')[0].firstChild.nodeValue,items[i].getElementsByTagName('valeur')[0].firstChild.nodeValue,false,true) document.getElementById('groupement').options[i]=myOption; } } } // Ici on va voir comment faire du post xhr.open("POST","cmbgroupement22.jsp",true); // ne pas oublier ça pour le post xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // ne pas oublier de poster les arguments // ici, l'id de l'auteur sel2 = document.getElementById('projet'); idprojet = sel2.options[sel2.selectedIndex].value; sel = document.getElementById('tranche'); idtranche = sel.options[sel.selectedIndex].value; xhr.send("idProjet="+idprojet+ "&idTranche="+idtranche); } </script> <body onload='change()'> <form method="POST" action="NouveauBien"> <fieldset style="padding: 2"> <legend>Information sur le Bien</legend> <b>Identificateur : <input type="text" name="id_bien" size="20"></b><p> <b>GH : <input type="text" name="gh" size="20"></b></p> </fieldset><p> </p> <fieldset style="width: 500px"> <legend>Information sur Projet</legend> <label>Projet</label> <select name="projet" id='projet' onchange='change()'> <% Projet prj = (Projet) application.getAttribute("prj"); Collection prjs = ProjetDAO.getProjetId(); if (prjs != null) { if (prjs.size() > 0) { for (Iterator iterator = prjs.iterator(); iterator.hasNext(); ) { Projet prjts = (Projet) iterator.next (); %> <OPTION value ="<%=prjts.getCode_projet()%>"> <%out.print(prjts.getLibelle());%> </OPTION> <% } } } %> </select> <label>Tranche</label> <div id='tranche' style='display:inline'> <select name='tranche2' onchange='change2()'> <option value='-1'>Choisir un projet</option> </select> </div> <label>Groupement</label> <div id='groupement' style='display:inline'> <select name='groupement2'> <option value='-1'>Choisir un projet ou tranche</option> </select> </div> </fieldset> <p><b>Superficie : </b> <input type="text" name="superficie" size="20"></p> <p> </p> <p><input type="submit" value="Enregistrer" name="B1"></p> <p> </p> <p> </p> </form> </body> </html>
parce que tu n'as pas tenu compte des références que tu utilises dans ta fonction.
Modifie la fonction en fonction des nouveaux id et name que tu utilises ...
(pour "tranche2" et "groupement2" tu devrais ajouter un id en plus du name, sinon ça ne fonctionnera que sous IE)
A+
est ce comme ça qu'il faut faire :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 <label>Tranche</label> <div id='tranche' style='display:inline'> <select name='tranche2' id='tranche' onchange='change2()'> <option value='-1'>Choisir un projet</option> </select> </div> <label>Groupement</label> <div id='groupement' style='display:inline'> <select name='groupement2' id='groupement'> <option value='-1'>Choisir un projet ou tranche</option> </select> </div>
Non : tu vois bien que tu as 2 fois id="tranche" ... ce qui est interdit.
Je t'avais donné un exemple, relis-le ...
A+
c'est ça ce que vous voulez dire ?
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 <label>Tranche</label> <div id='tranche' style='display:inline'> <select name='tranche2' onchange='change2()'> <option value='-1'>Choisir un projet</option> </select> </div> <label>Groupement</label> <div id='groupement' style='display:inline'> <select name='groupement2' > <option value='-1'>Choisir un projet ou tranche</option> </select> </div>
Oui, à condition que tu ais modifié dans ta fonctionenCode:document.getElementById('tranche')
etCode:document.getElementById('tranche2')
enCode:document.getElementById('groupement')
Je te conseillais aussi d'ajouterCode:document.getElementById('groupement2')
etCode:<select name='tranche2' id='tranche2' onchange='change2()'>
Sinon ça ne fonctionnera que sous IE ...Code:<select name='groupement2' id='groupement2'>
A+
avec la solution que vous m'avez donné, les combos tranche et groupement réagissent mais elles sont vides.
Re,
Fait nous voir ton code actuel.
le voilà :
Code:
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 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import="java.util.Vector,java.util.Enumeration,GC.bean.Bien, GC.bean.Projet,GC.bean.Tranche,GC.bean.Groupement,GC.dao.GroupementDAO, GC.dao.ProjetDAO,java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <script type='text/javascript'> 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; } /** * Méthode qui sera appelée sur le click du bouton */ function change() { //Si c'est AUCUN qui est sélectionné, il faut réinitialiser //les 2 autres combos et quitter var sel = document.getElementById('projet'); if (sel.options[sel.selectedIndex].value == -1) { document.getElementById('tranche2').options.length=0; document.getElementById('groupement2').options.length=0; return; } var xhr = getXhr(); // On défini ce qu'on va faire quand on aura la réponse xhr.onreadystatechange = function() { //attendons dque le requete soit finie... if(xhr.readyState == 4 && xhr.status == 200){ //alert(xhr.responseText); var rst = xhr.responseXML; var items=rst.getElementsByTagName('element'); document.getElementById('tranche2').options.length=0; //penser à réinitialiser aussi id_ref document.getElementById('groupement2').options.length=0; for(var i=0;i<items.length;i++) { var myOption = new Option(items[i].getElementsByTagName('option')[0].firstChild.nodeValue,items[i].getElementsByTagName('valeur')[0].firstChild.nodeValue,false,true) document.getElementById('tranche2').options[i]=myOption; } //mise à jour de id_ref pour le 1er prenom affiché (sinon incohérence //au niveau de l'affichage) change2(); } } // Ici on va voir comment faire du post xhr.open("POST","cmbtranche22.jsp",true); // ne pas oublier ça pour le post xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // ne pas oublier de poster les arguments // ici, l'id de l'auteur sel = document.getElementById('projet'); idprojet = sel.options[sel.selectedIndex].value; xhr.send("idProjet="+idprojet); } function change2() { //si un seul prenom... if (document.getElementById('tranche2').options.length==1) { //on vide la derniere combo document.getElementById('groupement2').options.length=0; //on quitte return; } var xhr = getXhr(); // On défini ce qu'on va faire quand on aura la réponse xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200){ // alert(xhr.responseText); var rst = xhr.responseXML; var items=rst.getElementsByTagName('element'); document.getElementById('groupement2').options.length=0; for(var i=0;i<items.length;i++) { var myOption = new Option(items[i].getElementsByTagName('option')[0].firstChild.nodeValue,items[i].getElementsByTagName('valeur')[0].firstChild.nodeValue,false,true) document.getElementById('groupement2').options[i]=myOption; } } } // Ici on va voir comment faire du post xhr.open("POST","cmbgroupement22.jsp",true); // ne pas oublier ça pour le post xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // ne pas oublier de poster les arguments // ici, l'id de l'auteur sel2 = document.getElementById('projet'); idprojet = sel2.options[sel2.selectedIndex].value; sel = document.getElementById('tranche2'); idtranche = sel.options[sel.selectedIndex].value; xhr.send("idProjet="+idprojet+ "&idTranche="+idtranche); } </script> <body onload='change()'> <form method="POST" action="NouveauBien"> <fieldset style="padding: 2"> <legend>Information sur le Bien</legend> <b>Identificateur : <input type="text" name="id_bien" size="20"></b><p> <b>GH : <input type="text" name="gh" size="20"></b></p> </fieldset><p> </p> <fieldset style="width: 500px"> <legend>Information sur Projet</legend> <label>Projet</label> <select name="projet" id='projet' onchange='change()'> <% Projet prj = (Projet) application.getAttribute("prj"); Collection prjs = ProjetDAO.getProjetId(); if (prjs != null) { if (prjs.size() > 0) { for (Iterator iterator = prjs.iterator(); iterator.hasNext(); ) { Projet prjts = (Projet) iterator.next (); %> <OPTION value ="<%=prjts.getCode_projet()%>"> <%out.print(prjts.getLibelle());%> </OPTION> <% } } } %> </select> <label>Tranche</label> <div id='tranche' style='display:inline'> <select name='tranche' id='tranche2' onchange='change2()'> <option value='-1'>Choisir un projet</option> </select> </div> <label>Groupement</label> <div id='groupement' style='display:inline'> <select name='groupement' id='groupement2'> <option value='-1'>Choisir un projet ou tranche</option> </select> </div> </fieldset> <p><b>Superficie : </b> <input type="text" name="superficie" size="20"></p> <p> </p> <p><input type="submit" value="Enregistrer" name="B1"></p> <p> </p> <p> </p> </form> </body> </html>
Salut,
Pour la Nième fois, tu NE DOIS PAS avoir les mêmes name et id portés par deux balises différentes:
ERECode:
1
2
3 <div id='tranche' style='display:inline'> <select name='tranche' id='tranche2' onchange='change2()'>
Ok ok, voici la troisième mise à jour de mon code en prenant en compte se qu'a dit emmanuel, les combos réagissent mais elles sont vides
Code:
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 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import="java.util.Vector,java.util.Enumeration,GC.bean.Bien, GC.bean.Projet,GC.bean.Tranche,GC.bean.Groupement,GC.dao.GroupementDAO, GC.dao.ProjetDAO,java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <script type='text/javascript'> 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; } /** * Méthode qui sera appelée sur le click du bouton */ function change() { //Si c'est AUCUN qui est sélectionné, il faut réinitialiser //les 2 autres combos et quitter var sel = document.getElementById('projet'); if (sel.options[sel.selectedIndex].value == -1) { document.getElementById('tranche2').options.length=0; document.getElementById('groupement2').options.length=0; return; } var xhr = getXhr(); // On défini ce qu'on va faire quand on aura la réponse xhr.onreadystatechange = function() { //attendons dque le requete soit finie... if(xhr.readyState == 4 && xhr.status == 200){ //alert(xhr.responseText); var rst = xhr.responseXML; var items=rst.getElementsByTagName('element'); document.getElementById('tranche2').options.length=0; //penser à réinitialiser aussi id_ref document.getElementById('groupement2').options.length=0; for(var i=0;i<items.length;i++) { var myOption = new Option(items[i].getElementsByTagName('option')[0].firstChild.nodeValue,items[i].getElementsByTagName('valeur')[0].firstChild.nodeValue,false,true) document.getElementById('tranche2').options[i]=myOption; } //mise à jour de id_ref pour le 1er prenom affiché (sinon incohérence //au niveau de l'affichage) change2(); } } // Ici on va voir comment faire du post xhr.open("POST","cmbtranche22.jsp",true); // ne pas oublier ça pour le post xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // ne pas oublier de poster les arguments // ici, l'id de l'auteur sel = document.getElementById('projet'); idprojet = sel.options[sel.selectedIndex].value; xhr.send("idProjet="+idprojet); } function change2() { //si un seul prenom... if (document.getElementById('tranche2').options.length==1) { //on vide la derniere combo document.getElementById('groupement2').options.length=0; //on quitte return; } var xhr = getXhr(); // On défini ce qu'on va faire quand on aura la réponse xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200){ // alert(xhr.responseText); var rst = xhr.responseXML; var items=rst.getElementsByTagName('element'); document.getElementById('groupement2').options.length=0; for(var i=0;i<items.length;i++) { var myOption = new Option(items[i].getElementsByTagName('option')[0].firstChild.nodeValue,items[i].getElementsByTagName('valeur')[0].firstChild.nodeValue,false,true) document.getElementById('groupement2').options[i]=myOption; } } } // Ici on va voir comment faire du post xhr.open("POST","cmbgroupement22.jsp",true); // ne pas oublier ça pour le post xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // ne pas oublier de poster les arguments // ici, l'id de l'auteur sel2 = document.getElementById('projet'); idprojet = sel2.options[sel2.selectedIndex].value; sel = document.getElementById('tranche2'); idtranche = sel.options[sel.selectedIndex].value; xhr.send("idProjet="+idprojet+ "&idTranche="+idtranche); } </script> <body onload='change()'> <form method="POST" action="NouveauBien"> <fieldset style="padding: 2"> <legend>Information sur le Bien</legend> <b>Identificateur : <input type="text" name="id_bien" size="20"></b><p> <b>GH : <input type="text" name="gh" size="20"></b></p> </fieldset><p> </p> <fieldset style="width: 500px"> <legend>Information sur Projet</legend> <label>Projet</label> <select name="projet" id='projet' onchange='change()'> <% Projet prj = (Projet) application.getAttribute("prj"); Collection prjs = ProjetDAO.getProjetId(); if (prjs != null) { if (prjs.size() > 0) { for (Iterator iterator = prjs.iterator(); iterator.hasNext(); ) { Projet prjts = (Projet) iterator.next (); %> <OPTION value ="<%=prjts.getCode_projet()%>"> <%out.print(prjts.getLibelle());%> </OPTION> <% } } } %> </select> <label>Tranche</label> <div id='tranche' style='display:inline'> <select name='tranche22' id='tranche2' onchange='change2()'> <option value='-1'>Choisir un projet</option> </select> </div> <label>Groupement</label> <div id='groupement' style='display:inline'> <select name='groupement22' id='groupement2'> <option value='-1'>Choisir un projet ou tranche</option> </select> </div> </fieldset> <p><b>Superficie : </b> <input type="text" name="superficie" size="20"></p> <p> </p> <p><input type="submit" value="Enregistrer" name="B1"></p> <p> </p> <p> </p> </form> </body> </html>
est ce que le code ci-dessous est correcte ???
j'attend vos feed-back
:D
je veux dire ci-dessus ...
OK.
Ça "semble" mieux ... :mrgreen:
Par contre, il serait plus réaliste de faire d'abord fonctionner ta 1° liste (qui alimente la 2°), puis une fois que ça marchera, se pencher sur l'alimentation de la 3° à partir de la 2°.
Bref, procéder par étape, quoi ....
Parce qu'en essayant de tout faire fonctionner d'un coup ... difficile de cerner le(s) problème(s) :aie:
A+
voilà, j'ai suivi ton conseil, j'ai supprimé l'appel à la fonction change2() à partir de la fonction change(), ceci devrait normalement charger seulement la deuxième combo...
mais malgré ça, cela ne donne rien, voici le nouveau code:
Code:
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 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import="java.util.Vector,java.util.Enumeration,GC.bean.Bien, GC.bean.Projet,GC.bean.Tranche,GC.bean.Groupement,GC.dao.GroupementDAO, GC.dao.ProjetDAO,java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <script type='text/javascript'> 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; } /** * Méthode qui sera appelée sur le click du bouton */ function change() { //Si c'est AUCUN qui est sélectionné, il faut réinitialiser //les 2 autres combos et quitter var sel = document.getElementById('projet'); if (sel.options[sel.selectedIndex].value == -1) { document.getElementById('tranche2').options.length=0; document.getElementById('groupement2').options.length=0; return; } var xhr = getXhr(); // On défini ce qu'on va faire quand on aura la réponse xhr.onreadystatechange = function() { //attendons dque le requete soit finie... if(xhr.readyState == 4 && xhr.status == 200){ //alert(xhr.responseText); var rst = xhr.responseXML; var items=rst.getElementsByTagName('element'); document.getElementById('tranche2').options.length=0; //penser à réinitialiser aussi id_ref document.getElementById('groupement2').options.length=0; for(var i=0;i<items.length;i++) { var myOption = new Option(items[i].getElementsByTagName('option')[0].firstChild.nodeValue,items[i].getElementsByTagName('valeur')[0].firstChild.nodeValue,false,true) document.getElementById('tranche2').options[i]=myOption; } //mise à jour de id_ref pour le 1er prenom affiché (sinon incohérence //au niveau de l'affichage) } } // Ici on va voir comment faire du post xhr.open("POST","cmbtranche22.jsp",true); // ne pas oublier ça pour le post xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // ne pas oublier de poster les arguments // ici, l'id de l'auteur sel = document.getElementById('projet'); idprojet = sel.options[sel.selectedIndex].value; xhr.send("idProjet="+idprojet); } function change2() { //si un seul prenom... if (document.getElementById('tranche2').options.length==1) { //on vide la derniere combo document.getElementById('groupement2').options.length=0; //on quitte return; } var xhr = getXhr(); // On défini ce qu'on va faire quand on aura la réponse xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200){ // alert(xhr.responseText); var rst = xhr.responseXML; var items=rst.getElementsByTagName('element'); document.getElementById('groupement2').options.length=0; for(var i=0;i<items.length;i++) { var myOption = new Option(items[i].getElementsByTagName('option')[0].firstChild.nodeValue,items[i].getElementsByTagName('valeur')[0].firstChild.nodeValue,false,true) document.getElementById('groupement2').options[i]=myOption; } } } // Ici on va voir comment faire du post xhr.open("POST","cmbgroupement22.jsp",true); // ne pas oublier ça pour le post xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // ne pas oublier de poster les arguments // ici, l'id de l'auteur sel2 = document.getElementById('projet'); idprojet = sel2.options[sel2.selectedIndex].value; sel = document.getElementById('tranche2'); idtranche = sel.options[sel.selectedIndex].value; xhr.send("idProjet="+idprojet+ "&idTranche="+idtranche); } </script> <body onload='change()'> <form method="POST" action="NouveauBien"> <fieldset style="padding: 2"> <legend>Information sur le Bien</legend> <b>Identificateur : <input type="text" name="id_bien" size="20"></b><p> <b>GH : <input type="text" name="gh" size="20"></b></p> </fieldset><p> </p> <fieldset style="width: 500px"> <legend>Information sur Projet</legend> <label>Projet</label> <select name="projet" id='projet' onchange='change()'> <% Projet prj = (Projet) application.getAttribute("prj"); Collection prjs = ProjetDAO.getProjetId(); if (prjs != null) { if (prjs.size() > 0) { for (Iterator iterator = prjs.iterator(); iterator.hasNext(); ) { Projet prjts = (Projet) iterator.next (); %> <OPTION value ="<%=prjts.getCode_projet()%>"> <%out.print(prjts.getLibelle());%> </OPTION> <% } } } %> </select> <label>Tranche</label> <div id='tranche' style='display:inline'> <select name='tranche22' id='tranche2' onchange='change2()'> <option value='-1'>Choisir un projet</option> </select> </div> <label>Groupement</label> <div id='groupement' style='display:inline'> <select name='groupement22' id='groupement2'> <option value='-1'>Choisir un projet ou tranche</option> </select> </div> </fieldset> <p><b>Superficie : </b> <input type="text" name="superficie" size="20"></p> <p> </p> <p><input type="submit" value="Enregistrer" name="B1"></p> <p> </p> <p> </p> </form> </body> </html>
a mon avis le problème devrait provenir de la variable myOption, qui est d'ailleurs soulignée en rouge par eclipse, elle sert à quoi en fait ??