I have a page with a form that contains information to be entered into a database. One field is a date field which automatically retrieves the stored date, or, if no date stored enters today's date, when the form is loaded.
Button 1) replace the field contents with the date x days later than the current field contents, or
Button 2) replace the field contents with the date x days from today.
For the purpose of the exercise, lets assume x = 7 days.
(sounds a bit like an exam question 'ey?)
I hope this is what u r looking for
Post the following script in the <head> tag.
function getAssignDate( when )
var x = 7;
mydate = new Date();
mymonth = mydate.getMonth();
myweekday = mydate.getDate();
myyear = mydate.getYear();
if (myyear < 1000) myyear += 1900;
months = new Array ("January","February","March","April","May","June","July","August","September","October","November","December");//define arrays
var toThisField = document.myForm.thisDate;
if( 'newDate' == when )
toThisField.value = months[mymonth] + " " + new Number( myweekday + x ) + ", " + myyear;
toThisField.value = months[mymonth] + " " + myweekday + ", " + myyear;
And this in the <html>
<body onload="getAssignDate( 'today' )">
<input type="text" name="thisDate" value="" />
<input type="button" value="Click to enter new date" onclick="getAssignDate( 'newDate' );" />