I have a student simulation that has about 100 embedded dates in a text file. The dates are choreographed back in time from the date of the simulation. Each year I have to redo all the dates to match the date of the simulation before printing it out
I am trying to create a html file to run in my browser to recalculate all the dates based on the Activity Date in a textbox. Based on what I have found on the web I can calculate the days until the activity. I cannot figure out how to make the dates recalculate when the Recalculate Date button is clicked.
I just read that document.write only works when the form is loaded. I cannot find how to rewrite this so all the dates recalculate based on the textbox.
Here is what I have. Any help would be appreciated.
I am trying to create a html file to run in my browser to recalculate all the dates based on the Activity Date in a textbox. Based on what I have found on the web I can calculate the days until the activity. I cannot figure out how to make the dates recalculate when the Recalculate Date button is clicked.
I just read that document.write only works when the form is loaded. I cannot find how to rewrite this so all the dates recalculate based on the textbox.
Here is what I have. Any help would be appreciated.
Code:
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Robert Shaw" />
<title>Print Chart Test</title>
</head>
<script type="text/javascript">
function GetDaysToActivity() //calculates number of days until the Activity date
{
var dob1 = document.getElementById("activitydate");
var age1 = document.getElementById("daystoactivity");
var ms = 86400000
var dateAry = dob1.value.split("/");
var birthMonth = parseInt(dateAry[0]);
var birthDay = parseInt(dateAry[1]);
var birthYear = parseInt(dateAry[2]);
var birthDate = new Date(birthYear, birthMonth - 1, birthDay);
var currentDate = new Date();
var age = birthDate - currentDate; // result is number of milliseconds difference
var mtg = age/ms;
mtg = Math.ceil(mtg);
if(birthDate < currentDate) {
alert("Activity date cannot be in the past");
document.getElementById("activitydate").value ="";
document.printchart.activitydate.focus();
}
else {
age1.value = mtg;
}
}
</script>
<script type="text/javascript">
function ActivityDate(x) //calculates the dates in the text
{
var date = new Date();
var ms = 86400000
var mtg = document.getElementById("daystoactivity").value;
if (mtg < 1){
mtg = 0
};
var daysback = x - mtg;
var nd = date - (daysback * ms);
nd = new Date(nd);
var curr_day = ("0" + nd.getDate()).slice(-2);
var curr_month = ("0" + (nd.getMonth() + 1)).slice(-2);
var curr_year = nd.getFullYear();
return curr_month + "/" + curr_day + "/" + curr_year;
}
</script>
</head>
<body>
<div><form name="printchart">
<label>Future date of activity (mm/dd/yyyy): </label>
<input type="text" id="activitydate"name="activitydate" onblur="GetDaysToActivity()"/>
<script>document.printchart.activitydate.focus();</script>
<!--<input type="hidden" id="daystoactivity" name="daystoactivity" style="display: none;" /> -->
<input type="text" id="daystoactivity" name="daystoactivity" />
<input type="button" value="Recalculate Dates" onclick='DateActivity()' />
<input type="button" value="Print Chart" onclick="" />
</div>
<br />
<br />
<div>Activity Date = Today: <script>document.write(ActivityDate(0.0000001));</script> (This should be the same as the Activity Date)<br />
<br />
Activity Date = Yesterday: <script>document.write(ActivityDate(1));</script> (This should be the same as the Activity Date - 1)<br />
<br />
Activity Date = 30 days ago: <script>document.write(ActivityDate(30));</script><br />
</div>
</body>
</html>