IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

date javascript


Sujet :

JavaScript

  1. #1
    Membre régulier
    Inscrit en
    Novembre 2006
    Messages
    304
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Novembre 2006
    Messages : 304
    Points : 77
    Points
    77
    Par défaut date javascript
    je veux comparer deux date dans deux zone de texte , date début projet et date fin : j'ai trouvé un code javascript que j'ai insérer mais ca marche pas pourriez vous m'aider :
    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
    <%@ 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 DonnerFocus(nom) {
       document.forms[0].elements[nom].focus();
    }
    function datecomp(datesaisie,datecompar){
       var datedebut=datesaisie.value;
       var datefin=datecompar.value;
       //vérification du format -  si la date est saisie je commence le travail, ce si se termine à la fin
       if (datedebut!="") {
          if (datefin=='1'){
             //definition des variables champs pour reprendre le focus au bon endroit
             var rfocus="zddprj";
             }
             else {
             var rfocus="zdfprj";
             }
          //véfification du format de date et +
          if (!verifdate(datedebut)) {
             alert("Attention soit la date n'est pas correcte, soit elle n'est pas au format JJ/MM/AAAA");DonnerFocus(rfocus);return false;
          }
       //création d'un tableau ou je range la date début dans trois cases, si il y a des zero je les supprimme
       deb = new Array(3); 
       if (datedebut.substring(0,1)=="0"){
          deb[1]=parseInt(datedebut.substring(1,2));
          }
       else {
          deb[1]=parseInt(datedebut.substring(0,2));
          }
       if (datedebut.substring(3,4)=="0"){
          deb[2]=parseInt(datedebut.substring(4,5));
          }
       else {
          deb[2]=parseInt(datedebut.substring(3,5));
          }
       deb[3]=parseInt(datedebut.substring(6,10));
       
       //si la datefin contient 1 on vient du formulaire dateresadebut donc on compare avec la date du jour
       //dans ce cas on récupère un format de date javascript, on le transforme et on le range dans un tableau
       //je ne transforme pas la variable datfin que je réutilise plus loin
       if (datefin=='1') {
          datef=new Date();
          fin = new Array(3);
          fin[1]=datef.getDate();
          fin[2]=datef.getMonth()+1;
          fin[3]=datef.getYear();
          var message="la date de réservation ne peut être infèrieur à la date du jour";
       }
       //dans l'autre cas, on arrive du formulaire par dateresafin et datecompar=dateresadebut
       //on récupère la dateresadebut et on la range aussi dans un tableau mais comme la datedébut
       else {
          fin = new Array(3); 
          if (datefin.substring(0,1)=="0"){
             fin[1]=parseInt(datefin.substring(1,2));
          }
          else {
             fin[1]=parseInt(datefin.substring(0,2));
          }
          if (datefin.substring(3,4)=="0"){
             fin[2]=parseInt(datefin.substring(4,5));
          }
          else {
             fin[2]=parseInt(datefin.substring(3,5));
             }
          fin[3]=parseInt(datefin.substring(6,10));
          var message="la date de fin de réservation ne peut être infèrieure à la date de début";
       }
    
       //comparaison des dates 
    
          if (deb[3]<fin[3]) {
             alert(message);DonnerFocus(rfocus);return false;
             }
          else {
             if ((deb[3]== fin[3]) && (deb[2]<fin[2])){
                alert(message);DonnerFocus(rfocus);return false;
             }
             else {
                if ((deb[3]== fin[3]) && (deb[2]==fin[2]) && (deb[1]<fin[1])){
                alert(message);DonnerFocus(rfocus);return false;
                }
             }
          }
          //si la date de réservation dépasse un an on demande une confirmation
          if (datefin!='1'){
             if ((deb[3]-fin[3])>1){
                if (confirm("attention, vous avez réservé pour plus d'un an, confirmer ?")) {
                return true;
                }
                else {
                   return false;
                }
             }
          }
       return true;
       }
    }
    
     // Cette fonction vérifie le format JJ/MM/AAAA saisi et la validité de la date.
     // Le séparateur est défini dans la variable separateur
     
     function verifdate(d) {
      var dateaverifier=d
      // rangement de la date dans des variables
      if (dateaverifier.substring(0,1)=="0"){
             var j=parseInt(dateaverifier.substring(1,2));
          }
          else {
             var j=parseInt(dateaverifier.substring(0,2));
          }
          if (dateaverifier.substring(3,4)=="0"){
             var m=parseInt(dateaverifier.substring(4,5));
          }
          else {
             var m=parseInt(dateaverifier.substring(3,5));
             }
          var a=parseInt(dateaverifier.substring(6,10));
       //si la longueur est différent de 10 , problème
         if (dateaverifier.length != 10) {
             return false;
       }
       //les caratères / ne sont pas aux endroits attendus
       else {
          if((dateaverifier.charAt(2) != '/') && (dateaverifier.charAt(5) != '/')) {
             return false;
          }
       }
       //l'année n'est pa un chiffre
       if (isNaN(a)) {
          return false;
        }
       //le mois n'est pas un chiffre ou n'est pas compris entre 0 et12
         if ((isNaN(m))||(m<1)||(m>12)) {
          return false;
        }
       //test si il s'agit d'une année bissextile pour accepter le 29/02
       if (((a % 4)==0 && (a % 100)!=0) || (a % 400)==0){
             if ((isNaN(j)) || ((m!=2) && ((j<1)||(j>31))) || ((m==2) && ((j<1)||(j>29)))) {
                return false;
            }
       }
        else {
             if ((isNaN(j)) || ((m!=2) && ((j<1)||(j>31))) || ((m==2) && ((j<1)||(j>28)))){
             return false;
          }
       }
       return true;
    }
    
    //cette fonction test si caractères numériques
    function IsNumberString(NumStr) 
    {var regEx=/^[0-9]+$/; 
    var ret=false; 
    if (regEx.test(NumStr)) ret=true; 
    return ret; 
    } 
    </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">&nbsp;</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">&nbsp;</TD>
    	</TR>
    </TABLE></td>
      </tr>
      <tr><td><TABLE WIDTH="43%" align="center"><tr><td class="titre">Ajout projet : </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%">&nbsp;</td>
            <td width="53%"><input name="znomprj" type="text" class="zcontenu" id="znomprj"></td>
          </tr>
          <tr class="ligne1">
            <td class="labels">Date d&eacute;but </td>
            <td>&nbsp;</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>&nbsp;</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>&nbsp;</td>
            <td><input name="zdescprj" type="text" class="zcontenu" id="zdescprj"></td>
          </tr>
          <tr class="ligne2">
            <td class="labels">Etat</td>
            <td>&nbsp;</td>
            <td><input name="zetatprj" type="text" class="zcontenu" id="zetatprj"></td>
          </tr>
          <tr class="ligne1">
            <td class="labels">Responsable</td>
            <td>&nbsp;</td>
            <td><input name="zrespprj" type="text" class="zcontenu" id="zrespprj"></td>
          </tr>
          <tr class="ligne2">
            <td class="labels">Client</td>
            <td>&nbsp;</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>&nbsp;</td>
            <td><input name="zeqpprj" type="text" class="zcontenu" id="zeqpprj"></td>
          </tr>
          <tr class="ligne2">
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr class="ligne2">
            <td>&nbsp;</td>
            <td>&nbsp;</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&eacute;rer" onClick="compDate("zddprj","zdfprj")"></td>
                <td width="41%" scope="col"><input name="Submit2" type="reset" class="submit" value="annuler"></td>
    			<td width="11%">&nbsp;</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("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>

  2. #2
    Membre averti Avatar de jmulans
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    397
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juin 2006
    Messages : 397
    Points : 383
    Points
    383
    Par défaut
    bonjour,

    j'ai un peu la flemme de regarder ton code
    pour comparer les dates moi j'utilise cette fonction
    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
    function ComparerDates(date1,date2){
        // retourne 0 si les date sont les mêmes
        // retourne 1 si date1 est superieure
        // retourne 2 si date2 est superieure
     
            date1 = date1+"";
            date2 = date2+"";
     
            var jour1 = date1.substr(0,2);
            var mois1 = date1.substr(3,2);
            var annee1 = date1.substr(6,4);
     
            var jour2 = date2.substr(0,2);
            var mois2 = date2.substr(3,2);
            var annee2 = date2.substr(6,4);
     
            // Mise en place de la première date
            d1 = new Date(0);
            d1.setFullYear(annee1,mois1-1,jour1)
     
            // Mise en place de la seconde date
            d2 = new Date(0);
            d2.setFullYear(annee2,mois2-1,jour2)
     
            if(d1 > d2)
                return 1;
            else if(d1 < d2)
                return 2;
            else
                return 0;
        }

  3. #3
    Membre régulier
    Inscrit en
    Novembre 2006
    Messages
    304
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Novembre 2006
    Messages : 304
    Points : 77
    Points
    77
    Par défaut comparer date
    ok merci, est ce que t'a réussi à comparer tes dates avec ce code :
    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
    <script language="javascript">
    function ComparerDates(date1,date2){
            date1 = date1+"";
            date2 = date2+""; // Prq
            
            var jour1 = date1.substr(0,2);
            var mois1 = date1.substr(3,2);
            var annee1 = date1.substr(6,4);
            
            var jour2 = date2.substr(0,2);
            var mois2 = date2.substr(3,2);
            var annee2 = date2.substr(6,4);
            
            // Mise en place de la première date
            d1 = new Date(0);
            d1.setFullYear(annee1,mois1-1,jour1)
     
            // Mise en place de la seconde date
            d2 = new Date(0);
            d2.setFullYear(annee2,mois2-1,jour2)
            
            if(d1 > d2)
                return 1;
            else if(d1 < d2)
                return 2;
            else
                return 0;
        }
    </script>
    Mes dates sont inclus dans un formulaire dans deux zones de texte; voila ce que j'ai fait mais ca marche pas :
    [CODE]<input name="Submit" type="submit" class="submit" value="Ins&eacute;rer" onClick="ComparerDates(zddprj.value,zdfprj.value)">[/CODE]

  4. #4
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 641
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 641
    Points : 66 666
    Points
    66 666
    Billets dans le blog
    1
    Par défaut
    pour la comparaison de date un simple split reverse join suffit ...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    date1="01/06/2007";
    date2="01/05/2002";
     
    alert(date1.split('/').reverse.join('')<date2.split('/').reverse.join(''))
    quelle usines à gaz !!!

  5. #5
    Membre régulier
    Inscrit en
    Novembre 2006
    Messages
    304
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Novembre 2006
    Messages : 304
    Points : 77
    Points
    77
    Par défaut problème data javascript
    voila j'ai modifié selon ce que je veux :
    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
    <%@ 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 ComparerDates(date1,date2){
    alert(date1);
            date1 = date1+"";
            date2 = date2+"";
            
            var jour1 = date1.substr(0,2);
            var mois1 = date1.substr(3,2);
            var annee1 = date1.substr(6,4);
            
            var jour2 = date2.substr(0,2);
            var mois2 = date2.substr(3,2);
            var annee2 = date2.substr(6,4);
            
            // Mise en place de la première date
            d1 = new Date(0);
            d1.setFullYear(annee1,mois1-1,jour1)
     
            // Mise en place de la seconde date
            d2 = new Date(0);
            d2.setFullYear(annee2,mois2-1,jour2)
            
            if(d1 < d2){// j'ai fait ce test pour passer si la date inférieur et ne passe passer dans le cas contraire mais malheureusement il passe dans les deux cas !		    return true;
    			}else{
    		    alert("La date début doit être inferieur strictement à date fin");
                return false;
    		   }
        }
    </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">&nbsp;</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">&nbsp;</TD>
    	</TR>
    </TABLE></td>
      </tr>
      <tr><td><TABLE WIDTH="43%" align="center"><tr><td class="titre">Ajout projet : </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%">&nbsp;</td>
            <td width="53%"><input name="znomprj" type="text" class="zcontenu" id="znomprj"></td>
          </tr>
          <tr class="ligne1">
            <td class="labels">Date d&eacute;but </td>
            <td>&nbsp;</td>
            <td><input name="zddprj" type="text" class="cal" id="zddprj" style="cursor: text" onClick="ds_sh(this);" readonly="readonly"></td>
          </tr>
          <tr class="ligne2">
            <td class="labels">Date fin </td>
            <td>&nbsp;</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>&nbsp;</td>
            <td><input name="zdescprj" type="text" class="zcontenu" id="zdescprj"></td>
          </tr>
          <tr class="ligne2">
            <td class="labels">Etat</td>
            <td>&nbsp;</td>
            <td><select name="zetatprj" style="width:152">
      			<option>Compl&eacute;t&eacute;</option>
      			<option>En cours</option>
      			<option>En attente</option>
    			</select></td>
          </tr>
          <tr class="ligne1">
            <td class="labels">Responsable</td>
            <td>&nbsp;</td>
            <td><input name="zrespprj" type="text" class="zcontenu" id="zrespprj"></td>
          </tr>
          <tr class="ligne2">
            <td class="labels">Client</td>
            <td>&nbsp;</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>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr class="ligne2">
            <td>&nbsp;</td>
            <td>&nbsp;</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&eacute;rer" onClick="ComparerDates(zddprj.value,zdfprj.value)"></td>
                <td width="41%" scope="col"><input name="Submit2" type="reset" class="submit" value="annuler"></td>
    			<td width="11%">&nbsp;</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("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>

  6. #6
    Rédacteur
    Avatar de bigboomshakala
    Homme Profil pro
    Consultant Web .NET
    Inscrit en
    Avril 2004
    Messages
    2 077
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Consultant Web .NET
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2004
    Messages : 2 077
    Points : 2 757
    Points
    2 757
    Par défaut
    Citation Envoyé par SpaceFrog
    pour la comparaison de date un simple split reverse join suffit ...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    date1="01/06/2007";
    date2="01/05/2002";
     
    alert(date1.split('/').reverse.join('')<date2.split('/').reverse.join(''))
    quelle usines à gaz !!!
    c'est passé inaperçu

  7. #7
    Membre régulier
    Inscrit en
    Novembre 2006
    Messages
    304
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Novembre 2006
    Messages : 304
    Points : 77
    Points
    77
    Par défaut problème data javascript
    voila j'ai modifié selon ce que je veux :
    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
    <%@ 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 ComparerDates(date1,date2){
    alert(date1);
            date1 = date1+"";
            date2 = date2+"";
            
            var jour1 = date1.substr(0,2);
            var mois1 = date1.substr(3,2);
            var annee1 = date1.substr(6,4);
            
            var jour2 = date2.substr(0,2);
            var mois2 = date2.substr(3,2);
            var annee2 = date2.substr(6,4);
            
            // Mise en place de la première date
            d1 = new Date(0);
            d1.setFullYear(annee1,mois1-1,jour1)
     
            // Mise en place de la seconde date
            d2 = new Date(0);
            d2.setFullYear(annee2,mois2-1,jour2)
            
            if(d1 < d2){// j'ai fait ce test pour passer si la date inférieur et ne passe passer dans le cas contraire mais malheureusement il passe dans les deux cas !		    return true;
    			}else{
    		    alert("La date début doit être inferieur strictement à date fin");
                return false;
    		   }
        }
    </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">&nbsp;</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">&nbsp;</TD>
    	</TR>
    </TABLE></td>
      </tr>
      <tr><td><TABLE WIDTH="43%" align="center"><tr><td class="titre">Ajout projet : </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%">&nbsp;</td>
            <td width="53%"><input name="znomprj" type="text" class="zcontenu" id="znomprj"></td>
          </tr>
          <tr class="ligne1">
            <td class="labels">Date d&eacute;but </td>
            <td>&nbsp;</td>
            <td><input name="zddprj" type="text" class="cal" id="zddprj" style="cursor: text" onClick="ds_sh(this);" readonly="readonly"></td>
          </tr>
          <tr class="ligne2">
            <td class="labels">Date fin </td>
            <td>&nbsp;</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>&nbsp;</td>
            <td><input name="zdescprj" type="text" class="zcontenu" id="zdescprj"></td>
          </tr>
          <tr class="ligne2">
            <td class="labels">Etat</td>
            <td>&nbsp;</td>
            <td><select name="zetatprj" style="width:152">
      			<option>Compl&eacute;t&eacute;</option>
      			<option>En cours</option>
      			<option>En attente</option>
    			</select></td>
          </tr>
          <tr class="ligne1">
            <td class="labels">Responsable</td>
            <td>&nbsp;</td>
            <td><input name="zrespprj" type="text" class="zcontenu" id="zrespprj"></td>
          </tr>
          <tr class="ligne2">
            <td class="labels">Client</td>
            <td>&nbsp;</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>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr class="ligne2">
            <td>&nbsp;</td>
            <td>&nbsp;</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&eacute;rer" onClick="ComparerDates(zddprj.value,zdfprj.value)"></td>
                <td width="41%" scope="col"><input name="Submit2" type="reset" class="submit" value="annuler"></td>
    			<td width="11%">&nbsp;</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("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>

  8. #8
    Inactif
    Profil pro
    Inscrit en
    Novembre 2002
    Messages
    117
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 117
    Points : 142
    Points
    142
    Par défaut
    Si tu lisais mieux le topic tu verrais que SpaceFrog a donné une réponse claire et précise et 100x plus légère que le "truc" que tu utilises

  9. #9
    Membre régulier
    Inscrit en
    Novembre 2006
    Messages
    304
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Novembre 2006
    Messages : 304
    Points : 77
    Points
    77
    Par défaut problèmes date javascript
    la solution n'est pas commenté pourriez vous me l'expliquer !

  10. #10
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 641
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 641
    Points : 66 666
    Points
    66 666
    Billets dans le blog
    1
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    date1="01/06/2007"; // ici je renseigne une variable avec une date string au format français jj/mm/aaa
    date2="01/05/2002"; // pareil pour la seconde date
     
    alert(date1.split('/').reverse.join('')<date2.split('/').reverse.join(''))
    date1.split('/') créé un array de trois éléments jj , mm , aaaa

    le reverse va inverser l'ordre des éléments du tableau : aaaa , mm , aa
    le joint regroupe les elements de ce tableau en un seul string: aaaammjj

    il est ensuite facile de comparer:
    20070601
    20020501

  11. #11
    Membre régulier
    Inscrit en
    Novembre 2006
    Messages
    304
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Novembre 2006
    Messages : 304
    Points : 77
    Points
    77
    Par défaut problème date javascript
    bonjour, je l'ai testé il me retourne la date de la première zone : ddprj (date debut projet) ensuite il ajoute l'enregistrement a la base malgré que la date debut est supérieur a la date fin du projet, dans est ce qu'il y a pas une possiblité d'empécher l'ajout dans ce cas et le laisser seulement dans le cas contraire !

  12. #12
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 641
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 641
    Points : 66 666
    Points
    66 666
    Billets dans le blog
    1
    Par défaut
    tu n'est pas entrain de vouloir faire executer un bout de javascript au milieu de ton code php ?
    Tu as un formulaire ?
    tu as un onsubmit ?

  13. #13
    Membre régulier
    Inscrit en
    Novembre 2006
    Messages
    304
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Novembre 2006
    Messages : 304
    Points : 77
    Points
    77
    Par défaut Problème date javascript
    voila en gros ce que j'ai fait :
    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
    <%@ 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 ComparerDates(date1,date2){
    alert(date1);
            date1 = date1+"";
            date2 = date2+"";
                  
            alert(date1.split('-').reverse.join('')>date2.split('-').reverse.join(''));
        }
    </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">&nbsp;</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">&nbsp;</TD>
    	</TR>
    </TABLE></td>
      </tr>
      <tr><td><TABLE WIDTH="43%" align="center"><tr><td class="titre">Ajout projet : </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%">&nbsp;</td>
            <td width="53%"><input name="znomprj" type="text" class="zcontenu" id="znomprj"></td>
          </tr>
          <tr class="ligne1">
            <td class="labels">Date d&eacute;but </td>
            <td>&nbsp;</td>
            <td><input name="zddprj" type="text" class="cal" id="zddprj" style="cursor: text" onClick="ds_sh(this);" readonly="readonly"></td>
          </tr>
          <tr class="ligne2">
            <td class="labels">Date fin </td>
            <td>&nbsp;</td>
            <td><input name="zdfprj" type="text" class="cal" id="zdfprj"  style="cursor: text" onClick="ds_sh(this);" readonly="readonly"></td>
          </tr>
          <tr class="ligne1">
            <td class="labels">Description</td>
            <td>&nbsp;</td>
            <td><input name="zdescprj" type="text" class="zcontenu" id="zdescprj"></td>
          </tr>
          <tr class="ligne2">
            <td class="labels">Etat</td>
            <td>&nbsp;</td>
            <td><select name="zetatprj" style="width:152">
      			<option>Compl&eacute;t&eacute;</option>
      			<option>En cours</option>
      			<option>En attente</option>
    			</select></td>
          </tr>
          <tr class="ligne1">
            <td class="labels">Responsable</td>
            <td>&nbsp;</td>
            <td><input name="zrespprj" type="text" class="zcontenu" id="zrespprj"></td>
          </tr>
          <tr class="ligne2">
            <td class="labels">Client</td>
            <td>&nbsp;</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>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr class="ligne2">
            <td>&nbsp;</td>
            <td>&nbsp;</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&eacute;rer" onClick="ComparerDates(zddprj.value,zdfprj.value)"></></td>            <td width="41%" scope="col"><input name="Submit2" type="reset" class="submit" value="annuler"></td>
    			<td width="11%">&nbsp;</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("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>

  14. #14
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 641
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 641
    Points : 66 666
    Points
    66 666
    Billets dans le blog
    1
    Par défaut

    le code que j'ai donné n'est qu'un exemple de la façon la plus simple de comparer deux dates ...
    il ne fait qu'un alert rien de plus ...
    si tu ne lui demande pas de faire autre chose c'est un peu normal qu'il ne fasse rien de plus...

  15. #15
    Membre régulier
    Inscrit en
    Novembre 2006
    Messages
    304
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Novembre 2006
    Messages : 304
    Points : 77
    Points
    77
    Par défaut problème date javascript
    ok, par exemple si la ddprj est > a la date dfprj il ce qu'il va me retourner 16-08-2007 > 12-08-2007 ou quoi exactement, je parle seulement du message !

    et comment puis je lui demander de ne pas passer si ddprj > dfprj !

  16. #16
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 641
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 641
    Points : 66 666
    Points
    66 666
    Billets dans le blog
    1
    Par défaut
    un return false dans le onsubmit du form ...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    onsumbit =" return verifDates()"
    et ta focntion verifDates retourne true ou false en fonction de la comparaison des dates ...

  17. #17
    Rédacteur
    Avatar de bigboomshakala
    Homme Profil pro
    Consultant Web .NET
    Inscrit en
    Avril 2004
    Messages
    2 077
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Consultant Web .NET
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2004
    Messages : 2 077
    Points : 2 757
    Points
    2 757
    Par défaut
    Citation Envoyé par Maria1505
    ok, par exemple si la ddprj est > a la date dfprj il ce qu'il va me retourner 16-08-2007 > 12-08-2007 ou quoi exactement, je parle seulement du message !

    et comment puis je lui demander de ne pas passer si ddprj > dfprj !
    B * A = BA

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    if (date1.split('/').reverse.join('')<date2.split('/').reverse.join(''))
    {
      // ici date 1 < date2
    }
    else
    {
      // ici date 1 >= date2
    }

  18. #18
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 641
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 641
    Points : 66 666
    Points
    66 666
    Billets dans le blog
    1
    Par défaut
    et en raccourci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    return (date1.split('/').reverse.join('')<date2.split('/').reverse.join(''))

  19. #19
    Membre régulier
    Inscrit en
    Novembre 2006
    Messages
    304
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Novembre 2006
    Messages : 304
    Points : 77
    Points
    77
    Par défaut problème date javascript
    ok, j'ai testé ce que vous m'avez posté mais j'arrive plus à l'empecher de passer si le résultat est false dans "onsubmit" et je crois que la fonction validator pour la gestion des autres zones qui l'empeche de s'éxécuter correctement !

Discussions similaires

  1. [2.2.1] Date JavaScript et Date BIRT
    Par birt1976 dans le forum BIRT
    Réponses: 5
    Dernier message: 05/08/2008, 12h27
  2. Test sur les dates javascript
    Par mjs21 dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 25/06/2008, 10h50
  3. date + javascript
    Par youcef81 dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 10/06/2006, 19h27
  4. comparaison de dates javascript
    Par SpaceFrog dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 12/07/2005, 08h45
  5. [date][javascript][sql] récupération dans un formulaire
    Par Shaud7 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 16/12/2004, 15h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo