Bonjour à tous,
Voilà mon souci, j'ai l'impression que je ne sais pas déclarer une variable globale !!!!!!!

Je réalise un calendrier (en fait deux calendriers qui seront liés entre eux).

Voilà la code de ma page qui va charger mes deux calendriers:

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
 
<HTML>
<HEAD>
<script language='javascript'>
 
 
</script>
<script language="javascript" src="./calendrier_function.js" type="text/javascript">
 
</script>
</HEAD>
<BODY>
 
<DIV id='calendrier1'>
<form name='calendar1'>
<input type='text' name='calendar1_date'>
<input type='hidden' name='hidden1' value=''>
</form>
<script>Init_Calendar('calendar1');SwitchMonth('calendar1',TodayMonth1,TodayYear1,'next');</script>
</DIV>
 
<DIV id='calendrier2'>
<form name='calendar2'>
<input type='text' name='calendar2_date'>
</form>
<script>Init_Calendar('calendar2');SwitchMonth('calendar2',TodayMonth2,TodayYear2,'next');</script>
</DIV>
 
</BODY>
</HTML>
Et voilà mon code javascript:
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
 
var WeekDay=new Array("L","M","M","J","V","S","D");
var Month=new Array("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Nomvembre","Décembre");
var NbJourMonth=new Array("31","28","31","30","31","30","31","31","30","31","30","31");
var today=new Date();
var TodayDay1=today.getDay();
var TodayMonth1=today.getMonth();
var TodayYear1=today.getYear();
var TodayDay2=TodayDay1;
var TodayMonth2=TodayMonth1;
var TodayYear2=TodayYear1;  
 
function Init_Calendar(Instance)
{
 
      document.write("<TABLE width=20% bgcolor='ffcccc'>");
      document.write("<TR>");
      document.write("<TD>");
      document.write("    <TABLE width=100% border=0>");
      document.write("    <TR height=18>");
      document.write("    <TD class='calendrier' colspan=2 width='10%' align='left'><a href='#' onclick=SwitchMonth('"+Instance+"','"+(TodayMonth1-1)+"','"+TodayYear1+"','previous');><img src='../images/fg.gif' border=0 ></a></TD>");
      document.write("    <TD class='calendrier' colspan=3 width='80%' align='center'><DIV id='mois"+Instance+"'></DIV></TD>");
      document.write("    <TD class='calendrier' colspan=2 width='10%' align='right'><a href='#'><img src='../images/fd.gif' border=0 onclick=SwitchMonth('"+Instance+"','"+(TodayMonth1+1)+"','"+TodayYear1+"','next');></a></TD>");
      document.write("    </TR>");
      document.write("    </TABLE>");
      document.write("</TD>");
      document.write("</TR>");
 
      document.write("<TR>");
      document.write("<TD>");
      document.write("    <TABLE width=100% border=0 cellspacing=1>");
      document.write("    <TR>");
      for(i=0;i<7;i++)
      {
            document.write("<TD class='Calendrier_Jour'>"+WeekDay[i]+"</TD>");
      }
 
      document.write("</TR>");
 
      for(i=0;i<6;i++)
      {
            document.write("<TR height=15>");
            for(j=0;j<7;j++)
            {
                  cell=Instance+""+i+""+j;
                  if(j==5 || j==6)
                  {
                          document.write("<TD class='Calendrier_DayOff' width='14,3%' id='"+cell+"'>cell"+i+""+j+"</TD>");
                  }
                  else
                  {
                        document.write("<TD class='Calendrier' width='14,3%' id='"+cell+"' onMouseOver=this.className='Calendrier_over' onMouseOut=this.className='calendrier' onclick=ReturnValue('"+Instance+"',"+i+","+j+")>"+Instance+""+i+""+j+"</TD>");
                  }
            }
            document.write("</TR>");
      }
 
      document.write("</TABLE>");
      document.write("</TD>");
      document.write("</TR>");
      document.write("</TABLE>");
}
 
 
 
function SwitchMonth(Instance,ThisMonth,ThisYear,mode)
{
 
    alert(Instance+" "+ThisMonth+" "+ThisYear+" "+mode);   
 
    for(i=0;i<6;i++)
    {
          for(j=0;j<7;j++)
          {
                document.getElementById(Instance+""+i+""+j).innerHTML="";
          }
    }
    /*ThisYear=CurrentYear;*/
    if(ThisMonth>11 && mode=='next')
    {
        ThisYear++;
        ThisMonth=0;
    }
    if(ThisMonth<0 && mode=='previous')
    {
        ThisYear--;
        ThisMonth=11;
    }
    var mois='mois'+Instance;
    document.getElementById(mois).innerHTML="<p align='center'><font size=1 family='tahoma'><b>"+Month[ThisMonth]+" "+ThisYear+"</b></font></p>";
    /*CurrentMonth=ThisMonth;
    CurrentYear=ThisYear;*/
    var NbJours=NbJourMonth[ThisMonth];
    if(ThisYear%4==0 && ThisMonth==1)
    {
        NbJours++;
    }
        FirstDate=new Date(ThisYear,ThisMonth,1);
        FirstDay=FirstDate.getDay();
        FirstDay=(FirstDay+6)%7;        
        for(i=1;i<=NbJours;i++)
        {
            var ThisDate=new Date(ThisYear,ThisMonth,i);
            var ThisDay=ThisDate.getDay();
            ThisDay=(ThisDay+6)%7;/* Tableau va du dimanche au samedi: dimanche->0 samedi->6 Nous on veut lundi->0 dimanche 6, d'où (+6%7)*/
            var ThisMonth=ThisDate.getMonth();
            var ThisYear=ThisDate.getYear();
            var cell=Instance+""+Math.floor((i-1+FirstDay)/7)+""+ThisDay;
            document.getElementById(cell).innerHTML=i;
            if(ThisDay==5 || ThisDay==6)
            {
                  if(document.getElementById(cell).firstChild.data!="")
                  {
                      document.getElementById(cell).className="Calendrier_DayOff";
                  }
                  else
                  {
                      document.getElementById(cell).className="Calendrier";
 
                  }
            }
        }
 
        if(Instance=='calendar1')
        {
 
            TodayMonth1=ThisMonth;
            TodayYear1=ThisYear;
            alert(TodayMonth1+"  "+TodayYear1);
        }
 
}
function ReturnValue(Instance,week,day)
{
 
    var cell=Instance+""+week+""+day;
    CurrentMonth+=1;
    if(CurrentMonth<10)
    {
        CurrentMonth="0"+CurrentMonth;
    }
    if (document.getElementById(cell).firstChild.data<10)
    {
        var CurrentDay="0"+document.getElementById(cell).firstChild.data;
    }
    else
    {
        var CurrentDay=document.getElementById(cell).firstChild.data;
    }
    if(Instance=='calendar1')
    {
        document.forms.calendar1.calendar1_date.value=CurrentDay+"/"+CurrentMonth+"/"+CurrentYear;
    /*document.getElementById('calendrier').style.visibility='hidden';*/
    }
    else
    {
        document.forms.calendar2.calendar2_date.value=CurrentDay+"/"+CurrentMonth+"/"+CurrentYear;
    }
 
}
Je n'ai pas d'erreur de codage mais ma variable TodayMonth1 ne s'incrémente pas !!!!

Comment cela se fait ??