[Javascript] Bouton precedent

[Fermé]
Signaler
-
 Dv!L$ToN -
Bonjour,

J'ai un petit probleme en javascript et j'espere que vous pourrez m'aider.

En fait,j'ai une page asp qui contient 2 bouton radio (holiday et all staff),une liste deroulante contenant les mois de l'annee, et 3 autres boutons radio (2005 2006 2007), et un bouton submit.
Quand je cliaue sur submit,j'execute une requete sql qui va chercher la liste des employes de l'entrprise en vacance pour le mois et l'anne selectionnee.Le bouton holiday permet l affichage de seulement les personnes en vacances alors que all staff affiche tous les employes.

Mon but est d'avoir de chaque cote de mon tableau un bouton precedent et un bouton suivant permettant de naviguer facilement vers le mois precedent ou suivant celui selectionne.

Je pensai le faire via une fonction javascript ms je n'y arrive pas

Je sais pas si voius pourrez m'aidez.
Je vous met mon code pour voir.

<%@language = VBScript %>
<!--#include file="Local.asp" -->
<!--#include file="config.asp" -->
<!--#include file="fcts_char.asp" -->
<!--#include file="fcts_requests.asp" -->
<!--#include file="adovbs.inc"-->
<%
PersonID = session ("PersonID")
If PersonID="" Then
personID = login() 'trying to log in automatically using windows username
if PersonID = 0 Then
response.redirect "login.asp?type=6"
end if
End If

'today is the day of today
dim today
today = Date()

'current_month is the current month
dim current_month
current_month = Month(today)
if current_month<10 then
current_month ="0"&current_month
end if

'current_year is the current year
dim current_year
current_year = Year(today)

'we recover the chosen type of holiday(all staff or just the holiday) chosen month and the chosen year
dim c
dim m
dim y
dim freshP

c = request("radCode")
m = request("Liste")
y = request("year")
freshP = request("freshP")
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
<title>Holiday Board</title>

<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name=ProgId content=VisualStudio.HTML>
<meta name=Originator content="Microsoft Visual Studio .NET 7.1">
<link rel="stylesheet" href="styles.css" type="text/css">

<!-- calendar stylesheet -->
<link rel="stylesheet" type="text/css" media="all" href="fcts_calendar/skins/aqua/theme.css" title="win2k-cold-1" />

<!-- main calendar program -->
<script type="text/javascript" src="fcts_calendar/calendar.js"></script>

<!-- language for the calendar -->
<script type="text/javascript" src="fcts_calendar/lang/calendar-en.js"></script>

<!-- the following script defines the Calendar.setup helper function, which makes
adding a calendar a matter of 1 or 2 lines of code. -->
<script type="text/javascript" src="fcts_calendar/calendar-setup.js"></script>

<script language="javascript">
function Lien()
{
i = document.Choix.Liste.selectedIndex;
if (i == 0) return;
url = document.Choix.Liste.options[i].value;
parent.location.href = url;
}

//function to go to the previous month fir the holiday only
function moveDateP()
{
//the chosen month and chosen year
var mon = <%=m%>;
var year = <%=y%>;

//the new month and the new year
var NewMon;
var NewYear;

//if the chosen month is January then
//the previous month is december
//and the year is the previous year too
if (mon == 1)
{
NewMon = 12;
NewYear = year - 1;

//the parameters are passed with the get method
//we call the same page with new parameter which are the new year and the new month
document.Form1.method = "GET";
document.Form1.action = "Holiday_board2.asp?freshP=1";
//document.Form1.action = "Holiday_board2.asp?radCode=holiday&Liste=" + NewMon + "&year = " + NewYear ;
document.Form1.submit();
}
//if the month is different than January
//the new month is the number of the chosen month - 1
//the new year is the same year
else
{
NewMon = mon - 1;
NewYear = year ;
//the parameters are passed with the get method
//we call the same page with new parameter which are the new year and the new month
document.Form1.method = "GET";
document.Form1.action = "Holiday_board2.asp?freshP=1";
//document.Form1.action = "Holiday_board2.asp?radCode=holiday&Liste=" + NewMon + "&year = " + NewYear ;
document.Form1.submit();
}
}

//function to go to the next month fir the holiday only
function moveDateN()
{
//the chosen month and chosen year
var mon = <%=m%>;
var year = <%=y%>;

//the new month and the new year
var NewMon;
var NewYear;

//if the chosen month is December then
//the next month is January
//and the year is the next year too
if (mon == 12)
{
NewMon = 1;
NewYear = year + 1;
//the parameters are passed with the get method
//we call the same page with new parameter which are the new year and the new month
//document.Form2.method = "GET";
//document.Form2.action = "Holiday_board2.asp?radCode=holiday&Liste=" + NewMon + "&year = " + NewYear ;
//document.Form2.submit();
}
//if the month is different than December
//the new month is the number of the chosen month + 1
//the new year is the same year
else
{
NewMon = mon + 1;
NewYear = year ;
//the parameters are passed with the get method
//we call the same page with new parameter which are the new year and the new month
//document.Form2.method = "GET";
//document.Form2.action = "Holiday_board2.asp?radCode=holiday&Liste=" + NewMon + "&year = " + NewYear ;
//document.Form2.submit();
}

}

//function to go to the previous month fir the all staff
function moveDateP2()
{
//the chosen month and chosen year
var mon = <%=m%>;
var year = <%=y%>;

//the new month and the new year
var NewMon;
var NewYear;

//if the chosen month is January then
//the previous month is december
//and the year is the previous year too
if (mon == 1)
{
NewMon = 12;
NewYear = year - 1;
//the parameters are passed with the get method
//we call the same page with new parameter which are the new year and the new month
//document.Form3.method = "GET";
//document.Form3.action = "Holiday_board2.asp?radCode=all&Liste=" + NewMon + "&year = " + NewYear ;
//document.Form3.submit();
}
//if the month is different than January
//the new month is the number of the chosen month - 1
//the new year is the same year
else
{
NewMon = mon - 1;
NewYear = year ;
//the parameters are passed with the get method
//we call the same page with new parameter which are the new year and the new month
//document.Form3.method = "GET";
//document.Form3.action = "Holiday_board2.asp?radCode=all&Liste=" + NewMon + "&year = " + NewYear ;
//document.Form3.submit();
}
}

//function to go to the next month fir the all staff
function moveDateN2()
{
//the chosen month and chosen year
var mon = <%=m%>;
var year = <%=y%>;

//the new month and the new year
var NewMon;
var NewYear;

//if the chosen month is December then
//the next month is January
//and the year is the next year too
if (mon == 12)
{
NewMon = 1;
NewYear = year + 1;
//the parameters are passed with the get method
//we call the same page with new parameter which are the new year and the new month
//document.Form4.method = "GET";
//document.Form4.action = "Holiday_board2.asp?radCode=all&Liste=" + NewMon + "&year = " + NewYear ;
//document.Form4.submit();
}
//if the month is different than December
//the new month is the number of the chosen month + 1
//the new year is the same year
else
{
NewMon = mon + 1;
NewYear = year ;
//the parameters are passed with the get method
//we call the same page with new parameter which are the new year and the new month
//document.Form4.method = "GET";
//document.Form4.action = "Holiday_board2.asp?radCode=all&Liste=" + NewMon + "&year = " + NewYear ;
//document.Form4.submit();
}
}

</script>
</head>

<body>
<table width="60%" style="MARGIN-LEFT: 20%; MARGIN-RIGHT: 20%" ID="Table1">
<tr></tr>
<tr>
<td align="center" class="lrgBlacktxt">Holiday Board</td>
</tr>
<tr></tr>
<tr></tr>
</table>

<center>
<font face="arial" size="2">
<FORM NAME="Choix" ID="Choix" action="Holiday_board2.asp">
<input type="radio" name="radCode" value="holiday" checked> Holiday's only
<input type="radio" name="radCode" value="all"> All Staff


<p>
<SELECT NAME="Liste" size="1" style="width: 100; height: 23" class="box_2">
<OPTION VALUE="00" >Select month</option>
<OPTION VALUE="01" <%if m="01" then
response.Write("selected = "&chr(34)&"selected"&chr(34))
end if%>>January</option>
<OPTION VALUE="02" <%if m="02" then
response.Write("selected = "&chr(34)&"selected"&chr(34))
end if%>>February</option>
<OPTION VALUE="03" <%if m="03" then
response.Write("selected = "&chr(34)&"selected"&chr(34))
end if%>>March</option>
<OPTION VALUE="04" <%if m="04" then
response.Write("selected = "&chr(34)&"selected"&chr(34))
end if%>>April</option>
<OPTION VALUE="05" <%if m="05" then
response.Write("selected = "&chr(34)&"selected"&chr(34))
end if%>>May</option>
<OPTION VALUE="06" <%if m="06" then
response.Write("selected = "&chr(34)&"selected"&chr(34))
end if%>>June</option>
<OPTION VALUE="07" <%if m="07" then
response.Write("selected = "&chr(34)&"selected"&chr(34))
end if%>>July</option>
<OPTION VALUE="08" <%if m="08" then
response.Write("selected = "&chr(34)&"selected"&chr(34))
end if%>>August</option>
<OPTION VALUE="09" <%if m="09" then
response.Write("selected = "&chr(34)&"selected"&chr(34))
end if%>>September</option>
<OPTION VALUE="10" <%if m="10" then
response.Write("selected = "&chr(34)&"selected"&chr(34))
end if%>>October</option>
<OPTION VALUE="11" <%if m="11" then
response.Write("selected = "&chr(34)&"selected"&chr(34))
end if%>>November</option>
<OPTION VALUE="12" <%if m="12" then
response.Write("selected = "&chr(34)&"selected"&chr(34))
end if%>>December</option>
</SELECT>

<input type="radio" name="year" value="<%=current_year-1%>"> <%=current_year-1%>
<input type="radio" name="year" value="<%=current_year%>" checked> <%=current_year%>
<input type="radio" name="year" value="<%=current_year+1%>"> <%=current_year+1%>

</p>

<img src="images/submit.png" width="69" height="18" onClick="document.Choix.submit();" class="hand" ALT="Search the Database">

</FORM>
</font>
</center>
<%

dim code
code = request("radCode")

dim year_check
year_check = request("year")

'here, we recover the name of the chosen month
dim month_name
if m="01" then
month_name = "JANUARY"
elseif m="02" then
month_name = "FEBRUARY"
elseif m="03" then
month_name = "MARCH"
elseif m="04" then
month_name = "APRIL"
elseif m="05" then
month_name = "MAY"
elseif m="06" then
month_name = "JUNE"
elseif m="07" then
month_name = "JULY"
elseif m="08" then
month_name = "AUGUST"
elseif m="09" then
month_name = "SEPTEMBER"
elseif m="10" then
month_name = "OCTOBER"
elseif m="11" then
month_name = "NOVEMBER"
elseif m="12" then
month_name = "DECEMBER"
else month_name = "Here it is not a month"
end if

'dim nb_line
nb_line = CInt(nb_line)

'the number of columns represents the number of day that there is in the selected month
dim nb_column
nb_column = CInt(nb_column)

'the request permits to know how much person are
nb_people = 0
set search = Server.CreateObject("ADODB.Recordset")
search.ActiveConnection = MyConnection
search.Source = "select count(*) as nb_people from tblPeople where active=1"
search.Open()
if not search.EOF then
nb_people=search("nb_people")
end if
nb_line = nb_people
search.Close()

'If the month is January,March,May,July,August,October or December, the number of columns is 31 like the number of day of the month
'If the month is April,June,September or November, the number of columns is 30 like the number of day of the month
'If the month is February, we test if the year is a leap year of not. If not, the number of columns is 28 else the number of columns is 29
if(m="01" or m="03" or m="05" or m="07" or m="08" or m="10" or m="12") then
nb_column=31
elseif(m="04" or m="06" or m="09" or m="11") then
nb_column=30
elseif(m="02")then
if((year_check Mod 100 <> 0 and year_check Mod 4 = 0) or (year_check Mod 400 = 0))then
nb_column=29
else nb_column=28
end if
else response.Write("")
end if

'if the radio button checked is "all"
if code = "all" then
if m = "00" then
response.Write("<center><b><BIG>"&"You must choose a month"&"</BIG></b><center>")
else
'start_month is the first day of the chosen month
dim start_month
start_month = "01/"&m&"/"&year_check
start_month = CDate(start_month)

'end_month is the last day of the chosen month
dim end_month
end_month = nb_column&"/"&m&"/"&year_check
end_month = CDate(end_month)
response.write("<center>"&"<b><u>"&"<font face=arial size=2>"&" "&month_name&" "&year_check&" "&"</font>"&"</u></b>"&"</center>")
response.write("<br>")%>

<table align="center" ID="Table2">
<tr class="txt3">
<td class="lrgtxt" align="left" valign="bottom" width="100"> Legend : </td>
<td align="left" valign="bottom" width="20"> <img src="images/pink_holiday.bmp" hspace="1" width="20" height="20" align="middle" > </td>
<td align=left valign=bottom width="100"> entire day </td>
<td align="left" valign="bottom" width="20"> <img src="images/pink_half_holiday.bmp" hspace="1" width="20" height="20" > </td>
<td align=left valign=bottom width="50"> half a day </td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
</table>

<table align=center bordercolor=#000000 bgcolor=#000000 cellspacing=1 ID="Table3">
<!-- <form name="Form3" id="Form3" > -->
<input type=image align=left src="images/previous.png" onClick="moveDateP2();" class="hand">
<!-- </form> -->
<!-- <form name="Form4" id="Form4" > -->
<input type=image align=right src="images/next.png" onClick="moveDateN2();" class="hand">
<!-- </form> -->

<%'We post every day of the month%>
<% for k=0 to nb_column
if m="00" then
response.Write("")
else
if k=0 then %>
<tr>
<%response.Write("<td bgcolor=#ffffff>"&""&"</td>")
else
if k<10 then
k = "0"&k
end if
response.Write("<td bgcolor=#ffffff>"&"<font face=arial size=2>"&k&"</font>"&"</td>")
end if
end if
next%>

<%
'for each person,we get back all the informations about him/her.
for i=0 to nb_people
set search_people = Server.CreateObject("ADODB.Recordset")
search_people.ActiveConnection = MyConnection
search_people.Source = "select * from tblPeople where active=1 order by LastName"
search_people.Open()
next
while not search_people.EOF
%>
<tr>
<td bordercolor=#000000 bgcolor=#ffffff>
<% Name = search_people.Fields.Item("LastName")
FirstName = search_people.Fields.Item("FirstName")
response.Write("<font face=arial size=2>"&FirstName&" "&Name&"</font>")
response.Write("<br>")
%>
</td>
<%
set search_holiday = Server.CreateObject("ADODB.Recordset")
search_holiday.ActiveConnection = MyConnection
search_holiday.Source = "select * from tblholidayapproval H INNER JOIN tblPeople P ON P.PersonID = H.person_id where P.LastName = '"&Name&"' and P.FirstName='"&FirstName&"'"

for j=1 to nb_column
date_today = j&"/"&m&"/"&year_check
date_today = CDate(date_today)

dim week_day
week_day = weekDay(date_today)
week_day = CInt(week_day)

'if the day is saturday or sunday, we are in weekend
if week_day=1 or week_day=7 then
response.Write("<td bgcolor=#663399 >"&""&"</td>")
else
dim vacance
vacance=0
search_holiday.Open()
do while not search_holiday.EOF
start_hol = search_holiday.Fields.Item("holiday_start_date")
start_hol = CDate(start_hol)

end_hol = search_holiday.Fields.Item("holiday_end_date")
end_hol = CDate(end_hol)

dim half_day
half_day = search_holiday.Fields.Item("half_day")

if date_today=start_hol and date_today<=end_hol and half_day = 1 then
vacance=2
exit do
end if

if date_today>=start_hol and date_today<end_hol then
vacance=1
exit do
end if
search_holiday.MoveNext
loop
search_holiday.Close()

'if the person is in holiday then we color the day in blue else the person isn't in holiday
if vacance=1 then
response.Write("<td bgcolor=#ff33cc>"&""&"</td>")
elseif vacance=2 then
response.Write("<td bgcolor=#ff99ff>"&""&"</td>")
else
response.Write("<td bgcolor=#ffffec>"&""&"</td>")
end if
end if
next%>
</tr>

<%search_people.MoveNext
wend
search_people.Close()%>
</table>
<%end if%>

<%
'if the radio button checked is "holiday"
elseif code="holiday" then
if m ="00" then
response.Write("<center><b><BIG>"&"You must choose a month"&"</BIG></b></center>")
else
start_month = "01/"&m&"/"&year_check
start_month = CDate(start_month)

end_month = nb_column&"/"&m&"/"&year_check
end_month = CDate(end_month)

response.write("<center>"&"<b><u>"&"<font face=arial size=2>"&month_name&" "&year_check&"</font>"&"</u></b>"&"</center>")
response.write("<br>")%>

<table align="center" ID="Table5">
<tr class="txt3">
<td class="lrgtxt" align="left" valign="bottom" width="100"> Legend : </td>
<td align="left" valign="bottom" width="20"> <img src="images/pink_holiday.bmp" hspace="1" width="20" height="20" align="middle" > </td>
<td align=left valign=bottom width="100"> entire day </td>
<td align="left" valign="bottom" width="20"> <img src="images/pink_half_holiday.bmp" hspace="1" width="20" height="20" > </td>
<td align=left valign=bottom width="50"> half a day </td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
</table>

<table align=center bordercolor=#000000 bgcolor=#000000 cellspacing=1 ID="Table6">
<!--Form included the button previous month for the holiday only -->
<form name="Form1" id="Form1">
<input type=image align=left src="images/previous.png" onClick="moveDateP();" class="hand">
</form>
<!-- <form name="Form2" id="Form2"> -->
<input type=image align=right src="images/next.png" onClick="moveDateN();" class="hand">
<!-- </form> -->

<%for k=0 to nb_column
if m="00" then
response.Write("")
else%>
<%if k=0 then %>
<tr>
<%response.Write("<td bgcolor=#ffffff>"&""&"</td>")
else
if k<10 then
k = "0"&k
end if
response.Write("<td bgcolor=#ffffff>"&"<font face=arial size=2>"&k&"</font>"&"</td>")
end if
end if
next%>
</tr>

<%
'for each active person who is in holiday during the chosen month, we get back all the informations about him/her.
for i=0 to nb_people
set search_people = Server.CreateObject("ADODB.Recordset")
search_people.ActiveConnection = MyConnection
search_people.Source = "select distinct P.LastName,P.FirstName from tblholidayapproval H INNER JOIN tblPeople P ON P.PersonID = H.person_id where P.Active = 1 and holiday_start_date>='"&start_month&"' and holiday_start_date<='"&end_month&"' or holiday_end_date>='"&start_month&"' and holiday_end_date<='"&end_month&"' order by LastName"
search_people.Open()
next
while not search_people.EOF
%>

<tr>
<td bordercolor=#000000 bgcolor=#ffffff>
<% Name = search_people.Fields.Item("LastName")
FirstName = search_people.Fields.Item("FirstName")
response.Write("<font face=arial size=2>"&FirstName&" "&Name&"</font>")
response.Write("<br>")%>
</td>
<%
set search_holiday = Server.CreateObject("ADODB.Recordset")
search_holiday.ActiveConnection = MyConnection
search_holiday.Source = "select * from tblholidayapproval H INNER JOIN tblPeople P ON P.PersonID = H.person_id where P.LastName = '"&Name&"' and P.FirstName='"&FirstName&"'"

for j=1 to nb_column
date_today = j&"/"&m&"/"&year_check
date_today = CDate(date_today)

week_day = weekDay(date_today)
week_day = CInt(week_day)

'if the day is saturday or sunday, we are in weekend
if week_day=1 or week_day=7 then
response.Write("<td bgcolor=#663399>"&""&"</td>")
else
vacance=0
search_holiday.Open()
do while not search_holiday.EOF
vacance=0
start_hol = search_holiday.Fields.Item("holiday_start_date")
start_hol = CDate(start_hol)

end_hol = search_holiday.Fields.Item("holiday_end_date")
end_hol = CDate(end_hol)

half_day = search_holiday.Fields.Item("half_day")

if date_today=start_hol and date_today<=end_hol and half_day = true then
vacance=2
exit do
end if

if date_today>=start_hol and date_today<end_hol then
vacance=1
exit do
end if
search_holiday.MoveNext
loop
search_holiday.Close()

'if the person is in holiday then we color the day in blue else the person isn't in holiday
if vacance=1 then
response.Write("<td bgcolor=#ff33cc>"&""&"</td>")
elseif vacance=2 then
response.Write("<td bgcolor=#ff99ff>"&""&"</td>")
else
response.Write("<td bgcolor=#ffffec>"&""&"</td>")
end if
end if
next
%>
</tr>
<%search_people.MoveNext
wend
search_people.Close()%>
</table>
<%end if%>
<%end if%>
</body>

</html>


Merci beaucoup.
coyotegirl42

1 réponse

c'est imbuvable ton code tu devrai enlever ton post et refaire ta demande ! ! !
11
Merci

Quelques mots de remerciements seront grandement appréciés. Ajouter un commentaire

CCM 42674 internautes nous ont dit merci ce mois-ci