I've posted MUCH cleaner code with just the two fields needed to solve my problem. If I type in a date of 04/16/2011 in the "sentence date" field, then click the calculate button, the date 03/05/2011 is displayed in the "Due to Reviewer" field. It subtracts 42 days from the date enetred into the "Sentence Date" field.

My problem is, sometimes when I type in a date in the "Sentence Date", such as 04/16/2011, 42 days prior falls on a weekend & I need it to always be on a weekday. So with that said, is it possible to put some type on function in the code where if the date falls on a weekend (Saturday or Sunday), it will roll back & display Friday's date?

Thanks again for the help!



<html>
<head>
<script type="text/javascript">
var valid;

function d2(v) { return (v<10)?("0"+v):v; }

function dcheck(form) {

var s = form.sent_date.value;
var sent = new Date(s);
var dr = form.due_rev.value
var due_rev = new Date(dr);

if (isNaN(due_rev)) {
due_rev = new Date(sent.getFullYear(),sent.getMonth(),sent.getDate()-42);
}

form.sent_date.value = (sent.getFullYear()+0) + "-" + d2(sent.getMonth()+1) + "-" + d2(sent.getDate());
form.due_rev.value = (due_rev.getFullYear()+0) + "-" + d2(due_rev.getMonth()+1) + "-" + d2(due_rev.getDate());

return true;
}

</script>

</head>
<body>
<form method="post" action="add.php">

</select>
</br>

<b>Sentence Date: MM/DD/YYYY</b> <br />
<input type="text" name="sent_date" size="30" /><br />

<p><input type="button" value="Calculate" onclick="return dcheck(this.form);"> </p>

<b>Due to Reviewer/b> <br />
<input type="text" name="due_rev" size="30" /><br />

<br>

</form>
</body>
</html>