Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

Retain FormDate1, FormDate2, DatesDiv values after form submit javascript?

Hi,

Code is currently retaining month, week and year dropdown values after form submit. Would you please make changes in code so that Formdate1, Formdate2, DatesDiv values will also be retained.

Thanks
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <script src="cookie.js" type="text/javascript"></script> 
 
<script type="text/javascript">
/* Set weeks in month script
   Copyright (c) 2003-2009 Michel Plungjan "javascripts (a) plungjan.name" - comments welcome 
   If you found it useful, please visit http://plungjan.name/reward.html 
   or help an artist/musician at http://talent-aid.org/
*/
  
// Change the values below if needed:
var adjustYears=true; // fix the year drop down to be around now. If false, years must be hardcoded in form
var yearAdjustment=0; // how many years prior to this year
var numberOfYears =10; // how many years in the dropdown
var yearsDescending = true; // count down = true, up = false
 
var monthNames = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(',');
var suf = "th,st,nd,rd".split(',')
function setDate(theForm) {
  var year = theForm.year.options[theForm.year.selectedIndex].value
  var month = theForm.month.selectedIndex
  setWeeks(theForm,year,month)
  reportDay(theForm)
 }
function addSuffix(day) {
  var str = day.toString();
  var lastDigit = str.substring(str.length-1);
  return suf[lastDigit]?suf[lastDigit]:"th"
}
 
function reportDay(theForm,submitting) {
  var yyyy = theForm.year.value;
  var mm = theForm.month.selectedIndex;
  var dates=new Array();
  var day = theForm.day.options[theForm.day.selectedIndex].value;
  var startDate = new Date(yyyy,mm,day,0,0,0);
  for (var i=0;i<7;i++) {
    dates[i]=startDate.getTime();
    startDate.setDate(startDate.getDate()+1)
  }
  show(dates);
  if (submitting) {
    mm+=1; // js months start at 0
    if (mm<10) mm="0"+mm;
    if (day<10) day = "0"+day;
    if (setCookie) setCookie('week',yyyy+''+mm+''+day)
  }
}
function fmtDate(timeStamp) {
  var d = new Date(timeStamp)
  var yy = d.getFullYear().toString().substring(2)
  var mm = d.getMonth()+1;
  if (mm<10) mm="0"+mm; // comment this out if you do not want padding with 0
  var dd = d.getDate();
  if (dd<10) dd="0"+dd; // comment this out if you do not want padding with 0
  return ""+mm+"/"+dd+"/"+yy;
}
function show(dates) {
  var d1 = fmtDate(dates[0])
  var d2 = (dates.length>1)?fmtDate(dates[dates.length-1]):"";
 
  var text = 'Start date: ' + d1 + ((dates.length==1)?'':'<br />End date: ' +d2) 
  document.getElementById("datesDiv").innerHTML = text;
  document.forms[0].formdate1.value=d1;
  document.forms[0].formdate2.value=d2;
}
function formatTimestamp(date) {
  var yyyy = date.getFullYear();
  var mm = date.getMonth()+1;
  var dd = date.getDate();
  if (mm<10) mm = "0"+mm;
  if (dd<10) dd="0"+dd;
  return yyyy+"/"+mm+"/"+dd;
}	
 
function setWeeks(theForm,year,month) { 
  var d = new Date(year,month+1,0); // first day-1 in the coming month
  var daysInMonth = d.getDate();
  theForm.day.options.length=0;
  d.setDate(1); // first of this month
  for (var i=1;i<=daysInMonth;i++) {
    var date = d.getDate();
    if (d.getDay()==1) {
      theForm.day.options.length++;
      theForm.day.options[theForm.day.options.length-1] = new Option("The week of the "+date+addSuffix(date)+" of " +monthNames[d.getMonth()],date);
    }
    d.setDate(d.getDate()+1);
  }
}
 
function setWeek(theForm,year,month) { 
  var d = new Date(year,month+1,0); // first day-1 in the coming month
  var now = new Date();
  d.setHours(now.getHours(),now.getMinutes(),now.getSeconds(),0); // normalise
  now.setHours(now.getHours(),now.getMinutes(),now.getSeconds(),0);
  theForm.day.options.length=0;
 
  var thisWeek = 0;
  var mondayOffset = 1-now.getDay();
  d.setDate(now.getDate()+mondayOffset)
 
  if (month>d.getMonth()) {
  	theForm.month.selectedIndex = d.getMonth();
  }
  if (year>d.getFullYear()) theForm.year.selectedIndex++;
 
  var daysInMonth = new Date(d.getFullYear(),d.getMonth()+1,0).getDate();
  d.setDate(1); // first of the month
  
  for (i=1;i<=daysInMonth;i++) {
    d.setDate(d.getDate()+1);
    var date = d.getDate();
    if (d.getDay()==1) {
      theForm.day.options.length++;
      theForm.day.options[theForm.day.options.length-1] = new Option("The week of the "+date+addSuffix(date)+" of " +monthNames[d.getMonth()],date);//formatTimestamp(d))
    }
    if (now.getTime()==d.getTime()) {
      thisWeek =theForm.day.options.length-1; // the option just created
    } 
  }
  theForm.day.selectedIndex=thisWeek
}       
function setNow() {
  var now = new Date();
  var ySel = document.forms[0].year;
  var mSel = document.forms[0].month;
  var dSel = document.forms[0].day;
 
  var year = now.getFullYear();
  var month = now.getMonth();
 
  if (adjustYears) {
    ySel.options.length=0; // remove all 
 
    var firstYear = year + yearAdjustment;
    if (yearsDescending ) {
      firstYear = year - yearAdjustment;
      for (var i=firstYear, n=firstYear-numberOfYears;i>=n;i--) {
        ySel.options.length++
        ySel.options[ySel.options.length-1] = new Option(i,i)
      }
    } 
    else for (var i=firstYear, n=firstYear+numberOfYears;i<n;i++) {
      ySel.options.length++
      ySel.options[ySel.options.length-1] = new Option(i,i)
    }
  }
  var minYear = parseInt(ySel.options[0].value);
  var diff = year-minYear;
  ySel.selectedIndex=((diff)>0)?diff:0;
  mSel.selectedIndex = month;
  setWeek(document.forms[0],year,month)
  reportDay(document.forms[0])
   
}
window.onload=function() { 
  setNow()
  var cook = (window.getCookie)? getCookie('week'):"";
  if (cook) { // 20091213
    var yyyy = cook.substring(0,4)
    var month = cook.substring(4,6);
    month-=1; // js months start at 0
    var date = cook.substring(6);
    for (var i=0;i<document.forms[0].year.length;i++) {
      if (document.forms[0].year.options[i].value==yyyy) {
        document.forms[0].year.options[i].selected=true;
        break
      }
    }
    setDate(document.forms[0])
    document.forms[0].month.selectedIndex=month;
    setDate(document.forms[0])
    for (var i=0;i<document.forms[0].day.length;i++) {
      if (document.forms[0].day.options[i].value==date) {
        document.forms[0].day.options[i].selected=true;
        break
      }
    }
  }
}
</script>
</head>
 
 
<body>
<form onSubmit="reportDay(this,true); " method="get" action="">
<input type="hidden" id="Hidden1" name="formdate1" />
<input type="hidden" id="Hidden2" name="formdate2" />
<select name="year" onChange="setDate(this.form)">
</select>
<select name="month" onChange="setDate(this.form)">
<option value="1">Jan
<option value="2">Feb
<option value="3">Mar
<option value="4">April
<option value="5">May
<option value="6">June
<option value="7">July
<option value="8">Aug
<option value="9">Sep
<option value="10">Oct
<option value="11">Nov
<option value="12">Dec
</select>
<select name="day" onChange="reportDay(this.form)"></select>
<br /><input type="submit" />
</form>
<hr />
<div id="datesDiv"></div> 
<div id="data">
<p><strong>April 13, 2009</strong><br>
<a href="/test.html" >test</a></p>
</div>
</body>
</html>

Open in new window

0
Saroj13
Asked:
Saroj13
  • 2
  • 2
1 Solution
 
OnthraxCommented:
Without storing the values somewhere like a cookie or database the only way to achieve this is to send them through the querystring.
0
 
Saroj13Author Commented:
Below code is storing month, week and year in a cookie. Would you please also store formdate1, formdate2, and datesdiv values in a cookie in the below code.

thanks
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
   <script type="text/javascript">
/* Set weeks in month script
   Copyright (c) 2003-2009 Michel Plungjan "javascripts (a) plungjan.name" - comments welcome 
   If you found it useful, please visit http://plungjan.name/reward.html 
   or help an artist/musician at http://talent-aid.org/
*/
  
var daysToKeep = 14; // default cookie life...
var today      = new Date(); 
var expiryDate = new Date(today.getTime() + (daysToKeep * 86400000));
 
 
/* Cookie functions originally by Bill Dortsch */
function setCookie (name,value,expires,path,theDomain,secure) { 
   value = escape(value);
   var theCookie = name + "=" + value + 
   ((expires)    ? "; expires=" + expires.toGMTString() : "") + 
   ((path)       ? "; path="    + path   : "") + 
   ((theDomain)  ? "; domain="  + theDomain : "") + 
   ((secure)     ? "; secure"            : ""); 
   document.cookie = theCookie;
} 
 
function getCookie(Name) { 
   var search = Name + "=" 
   if (document.cookie.length > 0) { // if there are any cookies 
      var offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         // set index of beginning of value 
         var end = document.cookie.indexOf(";", offset) 
         // set index of end of cookie value 
         if (end == -1) end = document.cookie.length 
         return unescape(document.cookie.substring(offset, end)) 
      } 
   } 
} 
function delCookie(name,path,domain) {
   if (getCookie(name)) document.cookie = name + "=" +
      ((path)   ? ";path="   + path   : "") +
      ((domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
} 
 
// Change the values below if needed:
var adjustYears=true; // fix the year drop down to be around now. If false, years must be hardcoded in form
var yearAdjustment=0; // how many years prior to this year
var numberOfYears =10; // how many years in the dropdown
var yearsDescending = true; // count down = true, up = false
 
var monthNames = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(',');
var suf = "th,st,nd,rd".split(',')
function setDate(theForm) {
  var year = theForm.year.options[theForm.year.selectedIndex].value
  var month = theForm.month.selectedIndex
  setWeeks(theForm,year,month)
  reportDay(theForm)
 }
function addSuffix(day) {
  var str = day.toString();
  var lastDigit = str.substring(str.length-1);
  return suf[lastDigit]?suf[lastDigit]:"th"
}
 
function reportDay(theForm,submitting) {
  var yyyy = theForm.year.value;
  var mm = theForm.month.selectedIndex;
  var dates=new Array();
  var day = theForm.day.options[theForm.day.selectedIndex].value;
  var startDate = new Date(yyyy,mm,day,0,0,0);
  for (var i=0;i<7;i++) {
    dates[i]=startDate.getTime();
    startDate.setDate(startDate.getDate()+1)
  }
  show(dates);
  if (submitting) {
    mm+=1; // js months start at 0
    if (mm<10) mm="0"+mm;
    if (day<10) day = "0"+day;
    if (setCookie) setCookie('week',yyyy+''+mm+''+day)
  }
}
function fmtDate(timeStamp) {
  var d = new Date(timeStamp)
  var yy = d.getFullYear().toString().substring(2)
  var mm = d.getMonth()+1;
  if (mm<10) mm="0"+mm; // comment this out if you do not want padding with 0
  var dd = d.getDate();
  if (dd<10) dd="0"+dd; // comment this out if you do not want padding with 0
  return ""+mm+"/"+dd+"/"+yy;
}
function show(dates) {
  var d1 = fmtDate(dates[0])
  var d2 = (dates.length>1)?fmtDate(dates[dates.length-1]):"";
 
  var text = 'Start date: ' + d1 + ((dates.length==1)?'':'<br />End date: ' +d2) 
  document.getElementById("datesDiv").innerHTML = text;
  document.forms[0].formdate1.value=d1;
  document.forms[0].formdate2.value=d2;
}
function formatTimestamp(date) {
  var yyyy = date.getFullYear();
  var mm = date.getMonth()+1;
  var dd = date.getDate();
  if (mm<10) mm = "0"+mm;
  if (dd<10) dd="0"+dd;
  return yyyy+"/"+mm+"/"+dd;
}	
 
function setWeeks(theForm,year,month) { 
  var d = new Date(year,month+1,0); // first day-1 in the coming month
  var daysInMonth = d.getDate();
  theForm.day.options.length=0;
  d.setDate(1); // first of this month
  for (var i=1;i<=daysInMonth;i++) {
    var date = d.getDate();
    if (d.getDay()==1) {
      theForm.day.options.length++;
      theForm.day.options[theForm.day.options.length-1] = new Option("The week of the "+date+addSuffix(date)+" of " +monthNames[d.getMonth()],date);
    }
    d.setDate(d.getDate()+1);
  }
}
 
function setWeek(theForm,year,month) { 
  var d = new Date(year,month+1,0); // first day-1 in the coming month
  var now = new Date();
  d.setHours(now.getHours(),now.getMinutes(),now.getSeconds(),0); // normalise
  now.setHours(now.getHours(),now.getMinutes(),now.getSeconds(),0);
  theForm.day.options.length=0;
 
  var thisWeek = 0;
  var mondayOffset = 1-now.getDay();
  d.setDate(now.getDate()+mondayOffset)
 
  if (month>d.getMonth()) {
  	theForm.month.selectedIndex = d.getMonth();
  }
  if (year>d.getFullYear()) theForm.year.selectedIndex++;
 
  var daysInMonth = new Date(d.getFullYear(),d.getMonth()+1,0).getDate();
  d.setDate(1); // first of the month
  
  for (i=1;i<=daysInMonth;i++) {
    d.setDate(d.getDate()+1);
    var date = d.getDate();
    if (d.getDay()==1) {
      theForm.day.options.length++;
      theForm.day.options[theForm.day.options.length-1] = new Option("The week of the "+date+addSuffix(date)+" of " +monthNames[d.getMonth()],date);//formatTimestamp(d))
    }
    if (now.getTime()==d.getTime()) {
      thisWeek =theForm.day.options.length-1; // the option just created
    } 
  }
  theForm.day.selectedIndex=thisWeek
}       
function setNow() {
  var now = new Date();
  var ySel = document.forms[0].year;
  var mSel = document.forms[0].month;
  var dSel = document.forms[0].day;
 
  var year = now.getFullYear();
  var month = now.getMonth();
 
  if (adjustYears) {
    ySel.options.length=0; // remove all 
 
    var firstYear = year + yearAdjustment;
    if (yearsDescending ) {
      firstYear = year - yearAdjustment;
      for (var i=firstYear, n=firstYear-numberOfYears;i>=n;i--) {
        ySel.options.length++
        ySel.options[ySel.options.length-1] = new Option(i,i)
      }
    } 
    else for (var i=firstYear, n=firstYear+numberOfYears;i<n;i++) {
      ySel.options.length++
      ySel.options[ySel.options.length-1] = new Option(i,i)
    }
  }
  var minYear = parseInt(ySel.options[0].value);
  var diff = year-minYear;
  ySel.selectedIndex=((diff)>0)?diff:0;
  mSel.selectedIndex = month;
  setWeek(document.forms[0],year,month)
  reportDay(document.forms[0])
   
}
window.onload=function() { 
  setNow()
  var cook = (window.getCookie)? getCookie('week'):"";
  if (cook) { // 20091213
    var yyyy = cook.substring(0,4)
    var month = cook.substring(4,6);
    month-=1; // js months start at 0
    var date = cook.substring(6);
    for (var i=0;i<document.forms[0].year.length;i++) {
      if (document.forms[0].year.options[i].value==yyyy) {
        document.forms[0].year.options[i].selected=true;
        break
      }
    }
    setDate(document.forms[0])
    document.forms[0].month.selectedIndex=month;
    setDate(document.forms[0])
    for (var i=0;i<document.forms[0].day.length;i++) {
      if (document.forms[0].day.options[i].value==date) {
        document.forms[0].day.options[i].selected=true;
        break
      }
    }
  }
}
</script>
</head>
 
 
<body>
<form onSubmit="reportDay(this,true); " method="get" action="">
<input type="hidden" id="Hidden1" name="formdate1" />
<input type="hidden" id="Hidden2" name="formdate2" />
<select name="year" onChange="setDate(this.form)">
</select>
<select name="month" onChange="setDate(this.form)">
<option value="1">Jan
<option value="2">Feb
<option value="3">Mar
<option value="4">April
<option value="5">May
<option value="6">June
<option value="7">July
<option value="8">Aug
<option value="9">Sep
<option value="10">Oct
<option value="11">Nov
<option value="12">Dec
</select>
<select name="day" onChange="reportDay(this.form)"></select>
<br /><input type="submit" />
</form>
<hr />
<div id="datesDiv"></div> 
<div id="data">
<p><strong>April 13, 2009</strong><br>
<a href="/test.html" >test</a></p>
</div>
</body>
</html>
 
Open in New Window Select All Tags: 
 
    

Open in new window

0
 
OnthraxCommented:
I am sorry but I am nog going through that entire script to change it as I simply do not have the time for that.

If that is what you wish you should close/accept this question and submit it again requesting to store this data into a cookie. This way people will know in advance whether they can help with coding.

Good luck.
0
 
sam2912Commented:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
   <script type="text/javascript">
/* Set weeks in month script
   Copyright (c) 2003-2009 Michel Plungjan "javascripts (a) plungjan.name" - comments welcome 
   If you found it useful, please visit http://plungjan.name/reward.html 
   or help an artist/musician at http://talent-aid.org/
*/
  
var daysToKeep = 14; // default cookie life...
var today      = new Date(); 
var expiryDate = new Date(today.getTime() + (daysToKeep * 86400000));
 
 
/* Cookie functions originally by Bill Dortsch */
function setCookie (name,value,expires,path,theDomain,secure) { 
   value = escape(value);
   var theCookie = name + "=" + value + 
   ((expires)    ? "; expires=" + expires.toGMTString() : "") + 
   ((path)       ? "; path="    + path   : "") + 
   ((theDomain)  ? "; domain="  + theDomain : "") + 
   ((secure)     ? "; secure"            : ""); 
   document.cookie = theCookie;
} 
 
function getCookie(Name) { 
   var search = Name + "=" 
   if (document.cookie.length > 0) { // if there are any cookies 
      var offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         // set index of beginning of value 
         var end = document.cookie.indexOf(";", offset) 
         // set index of end of cookie value 
         if (end == -1) end = document.cookie.length 
         return unescape(document.cookie.substring(offset, end)) 
      } 
   } 
} 
function delCookie(name,path,domain) {
   if (getCookie(name)) document.cookie = name + "=" +
      ((path)   ? ";path="   + path   : "") +
      ((domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
} 
 
// Change the values below if needed:
var adjustYears=true; // fix the year drop down to be around now. If false, years must be hardcoded in form
var yearAdjustment=0; // how many years prior to this year
var numberOfYears =10; // how many years in the dropdown
var yearsDescending = true; // count down = true, up = false
 
var monthNames = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(',');
var suf = "th,st,nd,rd".split(',')
function setDate(theForm) {
  var year = theForm.year.options[theForm.year.selectedIndex].value
  var month = theForm.month.selectedIndex
  setWeeks(theForm,year,month)
  reportDay(theForm)
 }
function addSuffix(day) {
  var str = day.toString();
  var lastDigit = str.substring(str.length-1);
  return suf[lastDigit]?suf[lastDigit]:"th"
}
 
function reportDay(theForm,submitting) {
  var formDate1 = document.forms[0].formdate1.value;
  var formDate2 = document.forms[0].formdate2.value;
  var datesDiv = document.getElementById('datesDiv').innerHTML;
  
  var yyyy = theForm.year.value;
  var mm = theForm.month.selectedIndex;
  var dates=new Array();
  var day = theForm.day.options[theForm.day.selectedIndex].value;
  var startDate = new Date(yyyy,mm,day,0,0,0);
  for (var i=0;i<7;i++) {
    dates[i]=startDate.getTime();
    startDate.setDate(startDate.getDate()+1)
  }
  show(dates);
  if (submitting) {
    mm+=1; // js months start at 0
    if (mm<10) mm="0"+mm;
    if (day<10) day = "0"+day;
    if (setCookie) setCookie('week',yyyy+''+mm+''+day+''+formDate1+''+formDate2+''+datesDiv);
  }
}
function fmtDate(timeStamp) {
  var d = new Date(timeStamp)
  var yy = d.getFullYear().toString().substring(2)
  var mm = d.getMonth()+1;
  if (mm<10) mm="0"+mm; // comment this out if you do not want padding with 0
  var dd = d.getDate();
  if (dd<10) dd="0"+dd; // comment this out if you do not want padding with 0
  return ""+mm+"/"+dd+"/"+yy;
}
function show(dates) {
  var d1 = fmtDate(dates[0])
  var d2 = (dates.length>1)?fmtDate(dates[dates.length-1]):"";
 
  var text = 'Start date: ' + d1 + ((dates.length==1)?'':'<br />End date: ' +d2) 
  document.getElementById("datesDiv").innerHTML = text;
  document.forms[0].formdate1.value=d1;
  document.forms[0].formdate2.value=d2;
}
function formatTimestamp(date) {
  var yyyy = date.getFullYear();
  var mm = date.getMonth()+1;
  var dd = date.getDate();
  if (mm<10) mm = "0"+mm;
  if (dd<10) dd="0"+dd;
  return yyyy+"/"+mm+"/"+dd;
}	
 
function setWeeks(theForm,year,month) { 
  var d = new Date(year,month+1,0); // first day-1 in the coming month
  var daysInMonth = d.getDate();
  theForm.day.options.length=0;
  d.setDate(1); // first of this month
  for (var i=1;i<=daysInMonth;i++) {
    var date = d.getDate();
    if (d.getDay()==1) {
      theForm.day.options.length++;
      theForm.day.options[theForm.day.options.length-1] = new Option("The week of the "+date+addSuffix(date)+" of " +monthNames[d.getMonth()],date);
    }
    d.setDate(d.getDate()+1);
  }
}
 
function setWeek(theForm,year,month) { 
  var d = new Date(year,month+1,0); // first day-1 in the coming month
  var now = new Date();
  d.setHours(now.getHours(),now.getMinutes(),now.getSeconds(),0); // normalise
  now.setHours(now.getHours(),now.getMinutes(),now.getSeconds(),0);
  theForm.day.options.length=0;
 
  var thisWeek = 0;
  var mondayOffset = 1-now.getDay();
  d.setDate(now.getDate()+mondayOffset)
 
  if (month>d.getMonth()) {
  	theForm.month.selectedIndex = d.getMonth();
  }
  if (year>d.getFullYear()) theForm.year.selectedIndex++;
 
  var daysInMonth = new Date(d.getFullYear(),d.getMonth()+1,0).getDate();
  d.setDate(1); // first of the month
  
  for (i=1;i<=daysInMonth;i++) {
    d.setDate(d.getDate()+1);
    var date = d.getDate();
    if (d.getDay()==1) {
      theForm.day.options.length++;
      theForm.day.options[theForm.day.options.length-1] = new Option("The week of the "+date+addSuffix(date)+" of " +monthNames[d.getMonth()],date);//formatTimestamp(d))
    }
    if (now.getTime()==d.getTime()) {
      thisWeek =theForm.day.options.length-1; // the option just created
    } 
  }
  theForm.day.selectedIndex=thisWeek
}       
function setNow() {
  var now = new Date();
  var ySel = document.forms[0].year;
  var mSel = document.forms[0].month;
  var dSel = document.forms[0].day;
 
  var year = now.getFullYear();
  var month = now.getMonth();
 
  if (adjustYears) {
    ySel.options.length=0; // remove all 
 
    var firstYear = year + yearAdjustment;
    if (yearsDescending ) {
      firstYear = year - yearAdjustment;
      for (var i=firstYear, n=firstYear-numberOfYears;i>=n;i--) {
        ySel.options.length++
        ySel.options[ySel.options.length-1] = new Option(i,i)
      }
    } 
    else for (var i=firstYear, n=firstYear+numberOfYears;i<n;i++) {
      ySel.options.length++
      ySel.options[ySel.options.length-1] = new Option(i,i)
    }
  }
  var minYear = parseInt(ySel.options[0].value);
  var diff = year-minYear;
  ySel.selectedIndex=((diff)>0)?diff:0;
  mSel.selectedIndex = month;
  setWeek(document.forms[0],year,month)
  reportDay(document.forms[0])
   
}
window.onload=function() { 
  setNow()
  var cook = (window.getCookie)? getCookie('week'):"";
  if (cook) { // 20091213
    var yyyy = cook.substring(0,4)
    var month = cook.substring(4,6);
    month-=1; // js months start at 0
    var date = cook.substring(6);
    for (var i=0;i<document.forms[0].year.length;i++) {
      if (document.forms[0].year.options[i].value==yyyy) {
        document.forms[0].year.options[i].selected=true;
        break
      }
    }
    setDate(document.forms[0])
    document.forms[0].month.selectedIndex=month;
    setDate(document.forms[0])
    for (var i=0;i<document.forms[0].day.length;i++) {
      if (document.forms[0].day.options[i].value==date) {
        document.forms[0].day.options[i].selected=true;
        break
      }
    }
  }
}
</script>
</head>
 
 
<body>
<form onSubmit="reportDay(this,true); " method="get" action="">
<input type="hidden" id="Hidden1" name="formdate1" />
<input type="hidden" id="Hidden2" name="formdate2" />
<select name="year" onChange="setDate(this.form)">
</select>
<select name="month" onChange="setDate(this.form)">
<option value="1">Jan
<option value="2">Feb
<option value="3">Mar
<option value="4">April
<option value="5">May
<option value="6">June
<option value="7">July
<option value="8">Aug
<option value="9">Sep
<option value="10">Oct
<option value="11">Nov
<option value="12">Dec
</select>
<select name="day" onChange="reportDay(this.form)"></select>
<br /><input type="submit" />
</form>
<hr />
<div id="datesDiv"></div> 
<div id="data">
<p><strong>April 13, 2009</strong><br>
<a href="/test.html" >test</a></p>
</div>
</body>
</html>
 
Open in New Window Select All Tags: 
 
    

Open in new window

0
 
sam2912Commented:
Did it solve the problem for you?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now