Hi Chris,
Thanks for the response. Unfortunately, that is what i'm already doing:
var dReturnDate =
eventObj.Source.selectSingleNode("/ar:absenceRequest/ar:leaves/ar:leave/ar:returnDate").text;
if(dStartDate != "" && dReturnDate != "")
{
var dStartDate2 = new
Date(dStartDate.substring(0,4),dStartDate.substring(5,7)-1,dStartDate.substring(8,10));
var dReturnDate2 = new
Date(dReturnDate.substring(0,4),dReturnDate.substring(5,7)-1,dReturnDate.substring(8,10));
//Calculate weekdays
var iTotalDays = ((dReturnDate2 - dStartDate2)/86400000)+1;
var dtDate = new Date(dStartDate2);
var iWeekDays = 0;
while (iTotalDays > 0)
{
var flag = 0;
if (new Date(dtDate).getDay() % 6 != 0)
{
for (i = 0; i <= BankHolidays.length - 1; i++)
{
if (dtDate - BankHolidays[i] >= 0 && dtDate - BankHolidays[i] <= 7200000)
flag = 1;
}
if (flag == 0)
iWeekDays++;
}
var dateInMs = dtDate.getTime();
dateInMs += 86400000;
dtDate.setTime(dateInMs);
iTotalDays = iTotalDays - 1;
}
eventObj.Source.selectSingleNode("/ar:absenceRequest/ar:leaves/ar:leave/ar:hours").text = iWeekDays;
}
else
{
eventObj.Source.selectSingleNode("/ar:absenceRequest/ar:leaves/ar:leave/ar:hours").text = "0.0";
}
The code (from the returnDate: OnAfterChnage event) takes the two dates and
calculates how many weekdays lies between them (excluding bank holidays) and
writes it to the /ar:hours field.
As before, this works fine for the first row in the table, however, any
subsequent rows simply update the first rows hours using the first rows
dates. Do i need to loop through all rows in the table each time?
Any suggestions would be greatly appreciated,
Cheers,
Martyn...
> I've had similiar problems in the past, not with dates but I dont think that
> impacts the solution.
[quoted text clipped - 25 lines]
> > Thanks in advance,
> > Martyn...
Martyn Lawson - 17 Aug 2005 16:38 GMT
Hi,
Just in case anyone looks at this and wonders how i got round it - buy a
book!!
After reading the book, i found the way to do it. It comes down to the way
the field text is obtained. I managed to get it working using:
var dStartDate = eventObj.Site.text;
var dReturnDate = eventObj.Site.nextSibling.nextSibling.text;
where Site.text is the text of the field firing the event and the
nextSibling.nextSibling gets the text from the next node in the datasource.
Obviously, previousSibling.previousSibling can also be used. To move through
the nodes use multiple '.nextSibling.nextSibling' in the line. It appears
that two only move one node. If there is quite a distance between nodes,
might be better looping using .nextNode()
Hope someone finds this useful,
Cheers,
Martyn...
> Hi Chris,
>
[quoted text clipped - 78 lines]
> > > Thanks in advance,
> > > Martyn...