bonjour, je travaille sur un formulaire que dois saisir l'utilisateur en saisissant la date début projet et sa date fin, bien sur la date début doit être inférieur à la date fin ! j'ai fais plusieur teste mais ca marche pas : en plus j'ai fais un calendrier dans les deux zone mais lorsque je teste sur les deux zone s'il sont vide il n'affiche pas de message ce qui me donne une erreur :
fichier validator :
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
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 <%@ include file="inc_connexion_auth.jsp" %> <html> <head> <title>Ajout Projet</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="style.css" rel="stylesheet" type="text/css"> <script language="javascript" src="script/gen_validatorv2.js"></script> <script language="javascript"> function compare(date_1, date_2){ diff = date_1-date_2; diff==0?diff:diff/Math.abs(diff); if(diff!=(-1)) alert(date_1+" : est supérieur de "+date_2); } </script> </head> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table class="ds_box" cellpadding="0" cellspacing="0" id="ds_conclass" style="display: none;"> <tr><td id="ds_calclass"></td></tr> </table> <script language="javascript" src="script/cal.js"></script> <table width="800" height="478" border="0" align="center" cellpadding=4 cellspacing="0" id="Tableau_01" style="border:solid 1px #99CC66"> <tr> <td height="155"><img src="images/index_01.jpg" width="800" height="147" alt=""></td> </tr> <tr> <td valign=top> <table width="100%" height="361" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="73"><TABLE WIDTH=788 BORDER=0 align="center" CELLPADDING=0 CELLSPACING=0> <TR> <TD width="13"> </TD> <TD width="75"> <IMG SRC="images/menuorigine_21.gif" WIDTH=57 HEIGHT=73 ALT="" name="img21" onmouseover='switchImage("img21", "images/menusurvol_21.gif")' onmouseout='switchImage("img21", "images/menuorigine_21.gif")'></TD> <TD width="3"> <IMG SRC="images/menuorigine_22.gif" WIDTH=3 HEIGHT=73 ALT="" ></TD> <TD width="43"> <IMG SRC="images/menuorigine_23.gif" WIDTH=43 HEIGHT=73 ALT="" name="img23" onmouseover='switchImage("img23", "images/menusurvol_23.gif")' onmouseout='switchImage("img23", "images/menuorigine_23.gif")'> </TD> <TD width="18"> <IMG SRC="images/menuorigine_24.gif" WIDTH=18 HEIGHT=73 ALT=""></TD> <TD width="44"> <IMG SRC="images/menuorigine_25.gif" WIDTH=44 HEIGHT=73 ALT="" name="img25" onmouseover='switchImage("img25", "images/menusurvol_25.gif")' onmouseout='switchImage("img25", "images/menuorigine_25.gif")'></TD> <TD width="15"> <IMG SRC="images/menuorigine_26.gif" WIDTH=15 HEIGHT=73 ALT=""></TD> <TD width="57"> <IMG SRC="images/menuorigine_27.gif" WIDTH=57 HEIGHT=73 ALT="" name="img27" onmouseover='switchImage("img27", "images/menusurvol_27.gif")' onmouseout='switchImage("img27", "images/menuorigine_27.gif")'></TD> <TD width="10"> <IMG SRC="images/menuorigine_28.gif" WIDTH=5 HEIGHT=73 ALT="" ></TD> <TD width="54"> <IMG SRC="images/menuorigine_29.gif" WIDTH=54 HEIGHT=73 ALT="" name="img29" onmouseover='switchImage("img29", "images/menusurvol_29.gif")' onmouseout='switchImage("img29", "images/menuorigine_29.gif")'></TD> <TD width="10"> <IMG SRC="images/menuorigine_30.gif" WIDTH=5 HEIGHT=73 ALT=""></TD> <TD width="43"> <IMG SRC="images/menuorigine_31.gif" WIDTH=43 HEIGHT=73 ALT="" name="img31" onmouseover='switchImage("img31", "images/menusurvol_31.gif")' onmouseout='switchImage("img31", "images/menuorigine_31.gif")'></TD> <TD width="16"> <IMG SRC="images/menuorigine_32.gif" WIDTH=16 HEIGHT=73 ALT=""></TD> <TD width="45"> <IMG SRC="images/menuorigine_33.gif" WIDTH=45 HEIGHT=73 ALT="" name="img33" onmouseover='switchImage("img33", "images/menusurvol_33.gif")' onmouseout='switchImage("img33", "images/menuorigine_33.gif")'></TD> <TD width="14"><img src="images/menuorigine_34.gif" width=14 height=73 alt=""></TD> <TD width="47"><img src="images/menuorigine_35.gif" width=47 height=73 alt="" name="img35" onMouseOver='switchImage("img35", "images/menusurvol_35.gif")' onMouseOut='switchImage("img35", "images/menuorigine_35.gif")' ></TD> <TD width="55"><img src="images/menuorigine_36.gif" width=55 height=73 alt=""></TD> <TD width="50"> <IMG SRC="images/menuorigine_37.gif" WIDTH=50 HEIGHT=73 ALT="" name="img37" onmouseover='switchImage("img37", "images/menusurvol_37.gif")' onmouseout='switchImage("img37", "images/menuorigine_37.gif")'></TD> <TD width="176" background="images/menuorigine_36.gif"> </TD> </TR> </TABLE></td> </tr> <tr> <td height="40"><form action="Trajoutprojet.jsp" method="post" name="AjoutProjet"> <br><br> <table width="43%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr class="ligne2"> <td width="40%" class="labels">Nom Projet </td> <td width="7%"> </td> <td width="53%"><input name="znomprj" type="text" class="zcontenu" id="znomprj"></td> </tr> <tr class="ligne1"> <td class="labels">Date début </td> <td> </td> <td><input name="zddprj" type="text" class="zcontenu" id="zddprj" style="cursor: text" onClick="ds_sh(this);" readonly="readonly"></td> </tr> <tr class="ligne2"> <td class="labels">Date fin </td> <td> </td> <td><input name="zdfprj" type="text" class="zcontenu" id="zdfprj" style="cursor: text" onClick="ds_sh(this);" readonly="readonly"></td> </tr> <tr class="ligne1"> <td class="labels">Description</td> <td> </td> <td><input name="zdescprj" type="text" class="zcontenu" id="zdescprj"></td> </tr> <tr class="ligne2"> <td class="labels">Etat</td> <td> </td> <td><input name="zetatprj" type="text" class="zcontenu" id="zetatprj"></td> </tr> <tr class="ligne1"> <td class="labels">Responsable</td> <td> </td> <td><input name="zrespprj" type="text" class="zcontenu" id="zrespprj"></td> </tr> <tr class="ligne2"> <td class="labels">Client</td> <td> </td> <td> <select name="zcltprj" id="zcltprj" style="width:152"> <% String requete="SELECT * FROM client"; rs = st.executeQuery(requete); while(rs.next()){ %> <option value="<%=rs.getInt("Id_Cl") %>"><%=rs.getString("Rai_Soc") %></option> <% } %> </select> </td> </tr> <tr class="ligne1"> <td class="labels">Equipe</td> <td> </td> <td><input name="zeqpprj" type="text" class="zcontenu" id="zeqpprj"></td> </tr> <tr class="ligne2"> <td> </td> <td> </td> <td> </td> </tr> <tr class="ligne2"> <td> </td> <td> </td> <td><table width="99%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="48%" scope="col"><input name="Submit" type="submit" class="submit" value="Insérer" onClick="javascript: compare(zddprj,zdfprj);"></td> <td width="41%" scope="col"><input name="Submit2" type="reset" class="submit" value="annuler"></td> <td width="11%"> </td> </tr> </table></td> </tr> </table> </form></td> </tr> <tr> <td><div align="center"><a href="projet.jsp"><img src="images/retour.jpg" width="85" height="85" border="0" class="ajouter"></a></div></td> </tr> </table> <script language="JavaScript" type="text/javascript"> var frmvalidator = new Validator("AjoutProjet"); frmvalidator.addValidation("znomprj","req","Nom projet : champ obligatoire "); frmvalidator.addValidation("zddprj","req","Date début projet : champ obligatoire"); frmvalidator.addValidation("zdfprj","req","Date début projet : champ obligatoire"); frmvalidator.addValidation("zetatprj","req","Etat : champ obligatoire"); frmvalidator.addValidation("zrespprj","req","Responsable projet : champ obligatoire"); frmvalidator.addValidation("zrespprj","alpha","Le nom du responsable doit être alphabétique"); </script> </td> </tr> <tr> <td><img src="images/index_03.jpg" width="800" height="91" alt=""></td> </tr> </table> </body> </html>
merci pour votre aide !
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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342 function Validator(frmname) { this.formobj=document.forms[frmname]; if(!this.formobj) { alert("BUG: couldnot get Form object "+frmname); return; } if(this.formobj.onsubmit) { this.formobj.old_onsubmit = this.formobj.onsubmit; this.formobj.onsubmit=null; } else { this.formobj.old_onsubmit = null; } this.formobj.onsubmit=form_submit_handler; this.addValidation = add_validation; this.setAddnlValidationFunction=set_addnl_vfunction; this.clearAllValidations = clear_all_validations; } function set_addnl_vfunction(functionname) { this.formobj.addnlvalidation = functionname; } function clear_all_validations() { for(var itr=0;itr < this.formobj.elements.length;itr++) { this.formobj.elements[itr].validationset = null; } } function form_submit_handler() { for(var itr=0;itr < this.elements.length;itr++) { if(this.elements[itr].validationset && !this.elements[itr].validationset.validate()) { return false; } } if(this.addnlvalidation) { str =" var ret = "+this.addnlvalidation+"()"; eval(str); if(!ret) return ret; } return true; } function add_validation(itemname,descriptor,errstr) { if(!this.formobj) { alert("BUG: the form object is not set properly"); return; }//if var itemobj = this.formobj[itemname]; if(!itemobj) { alert("BUG: Couldnot get the input object named: "+itemname); return; } if(!itemobj.validationset) { itemobj.validationset = new ValidationSet(itemobj); } itemobj.validationset.add(descriptor,errstr); } function ValidationDesc(inputitem,desc,error) { this.desc=desc; this.error=error; this.itemobj = inputitem; this.validate=vdesc_validate; } function vdesc_validate() { if(!V2validateData(this.desc,this.itemobj,this.error)) { this.itemobj.focus(); return false; } return true; } function ValidationSet(inputitem) { this.vSet=new Array(); this.add= add_validationdesc; this.validate= vset_validate; this.itemobj = inputitem; } function add_validationdesc(desc,error) { this.vSet[this.vSet.length]= new ValidationDesc(this.itemobj,desc,error); } function vset_validate() { for(var itr=0;itr<this.vSet.length;itr++) { if(!this.vSet[itr].validate()) { return false; } } return true; } function validateEmailv2(email) { // a very simple email validation checking. // you can add more complex email checking if it helps var splitted = email.match("^(.+)@(.+)$"); if(splitted == null) return false; if(splitted[1] != null ) { var regexp_user=/^\"?[\w-_\.]*\"?$/; if(splitted[1].match(regexp_user) == null) return false; } if(splitted[2] != null) { var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/; if(splitted[2].match(regexp_domain) == null) { var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/; if(splitted[2].match(regexp_ip) == null) return false; }// if return true; } return false; } function V2validateData(strValidateStr,objValue,strError) { var epos = strValidateStr.search("="); var command = ""; var cmdvalue = ""; if(epos >= 0) { command = strValidateStr.substring(0,epos); cmdvalue = strValidateStr.substr(epos+1); } else { command = strValidateStr; } switch(command) { case "req": case "required": { if(eval(objValue.value.length) == 0) { if(!strError || strError.length ==0) { strError = objValue.name + " : Champ obligatoire"; }//if alert(strError); return false; }//if break; }//case required case "maxlength": case "maxlen": { if(eval(objValue.value.length) > eval(cmdvalue)) { if(!strError || strError.length ==0) { strError = objValue.name + " : "+cmdvalue+" characters maximum "; }//if alert(strError + "\n[Current length = " + objValue.value.length + " ]"); return false; }//if break; }//case maxlen case "minlength": case "minlen": { if(eval(objValue.value.length) < eval(cmdvalue)) { if(!strError || strError.length ==0) { strError = objValue.name + " : " + cmdvalue + " characters minimum "; }//if alert(strError + "\n[Current length = " + objValue.value.length + " ]"); return false; }//if break; }//case minlen case "alnum": case "alphanumeric": { var charpos = objValue.value.search("[^A-Za-z0-9]"); if(objValue.value.length > 0 && charpos >= 0) { if(!strError || strError.length ==0) { strError = objValue.name+": Only alpha-numeric characters allowed "; }//if //alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); return false; }//if break; }//case alphanumeric case "num": case "numeric": { var charpos = objValue.value.search("[^0-9]"); if(objValue.value.length > 0 && charpos >= 0) { if(!strError || strError.length ==0) { strError = objValue.name+": Only digits allowed "; }//if alert(strError + "\n [la position d'erreur " + eval(charpos+1)+"]"); return false; }//if break; }//numeric case "alphabetic": case "alpha": { var charpos = objValue.value.search("[^A-Za-z]"); if(objValue.value.length > 0 && charpos >= 0) { if(!strError || strError.length ==0) { strError = objValue.name+": Only alphabetic characters allowed "; }//if alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); return false; }//if break; }//alpha case "alnumhyphen": { var charpos = objValue.value.search("[^A-Za-z0-9\-_]"); if(objValue.value.length > 0 && charpos >= 0) { if(!strError || strError.length ==0) { strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _"; }//if alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); return false; }//if break; } case "email": { if(!validateEmailv2(objValue.value)) { if(!strError || strError.length ==0) { strError = objValue.name+": entrer une adresse email valide"; }//if alert(strError); return false; }//if break; }//case email /*case "date" { if(compare(getDate(document.objValue.value,document.objValue.value))!=(-1) { strError = objValue.name+": est supérieur de "+ objValue.name; } alert(strError); }*/ case "lt": case "lessthan": { if(isNaN(objValue.value)) { alert(objValue.name+": Ce champ doit être un nombre"); return false; }//if if(eval(objValue.value) >= eval(cmdvalue)) { if(!strError || strError.length ==0) { strError = objValue.name + " : doit être inferieur à "+ cmdvalue; }//if alert(strError); return false; }//if break; }//case lessthan case "gt": case "greaterthan": { if(isNaN(objValue.value)) { alert(objValue.name+": Should be a number "); return false; }//if if(eval(objValue.value) <= eval(cmdvalue)) { if(!strError || strError.length ==0) { strError = objValue.name + " : value should be greater than "+ cmdvalue; }//if alert(strError); return false; }//if break; }//case greaterthan case "regexp": { if(!objValue.value.match(cmdvalue)) { if(!strError || strError.length ==0) { strError = objValue.name+": Invalid characters found "; }//if alert(strError); return false; }//if break; }//case regexp case "dontselect": { if(objValue.selectedIndex == null) { alert("BUG: dontselect command for non-select Item"); return false; } if(objValue.selectedIndex == eval(cmdvalue)) { if(!strError || strError.length ==0) { strError = objValue.name+": Choisir un element"; }//if alert(strError); return false; } break; }//case dontselect }//switch return true; }
Partager