Need fortnightly start date!
I've had a play with what you wrote and we're getting really close!
I've made the code add 14 days, not seven, and now it updates the original field. So its just about perfect! (see below)
The only thing left to do is determine the start date. Currently, it just finds the next wednesday after today. But I'm on a fortnightly roster, so it needs to find the next wednesday which starts a roster cycle.
For example, if my roster cycle starts today (18 March), then I'd like it display 18/03/09 in the input. If I looked at this page yesterday, it should still display 18/03/09 - as that is the beginning of the next roster cycle. If I look at this page tomorrow, id like it to display 01/04/09 - as that is the beginning of the next fortnight's roster... and so on into the future.
Thanks!
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function setNextWednesday(){
var date=new Date();
var DT=date.getDate();
var DY=date.getDay();
while(DY!=3){
date.setDate(DT++)
DY=date.getDay();
}
writeDate(date,'inDate');
}
function showFortnight(f){
var d=f['inDate'].value.split('/');
var date=new Date(Number(d[2]),Number(d[1])-1,Number(d[0]));
var DT=date.getDate();
date.setDate(DT+14); //changed from +7 to +14
writeDate(date,'inDate'); //changed from outDate to inDate
}
function writeDate(date,fname){
var DT=date.getDate();
var YYYY=date.getFullYear();
var MM=date.getMonth()+1;
DT<10?DT='0'+DT:null;MM<10?MM='0'+MM:null;
var f=document.getElementById('myForm');
f[fname].value=DT+'/'+MM+'/'+YYYY;
}
onload=setNextWednesday;
</script>
</head>
<body>
<form action="" id="myForm">
<input type="text" name="inDate" readonly="readonly"><input type="button" value="Next" onclick="showFortnight(this.form)">
</form>
</body>
</html>