Modify form date entered and populate another field with result

I have a form text field where a drop date for a mailing piece is entered. This field is followed by another field that needs to take the first date and subtract 48 hours (or two days) from it and automatically enter the value in it’s text field to give a date by which all materials for the mailing piece must be submitted.

[code]


Drop Date: Materials Date: [/code]

How do I take that initial entered date’s value and subtract the two days from it and get it to give a valid date to put in the second text field. Especially, for example, if the first date is the first day of a month and moving backwards two days would put the materials date into the previous month? Or even more of a question if the date is say Jan 1st of a new year and the materials date would be the month before and in the previous year?

I imagine it would involve some equation applied to the posted value of the first date to calculate the new date’s value but how would you account for different months or years?

Adriana

Sound like you need javascript solution to interactively populate the second date without submitting form data. Right?
But since you’ve posted this question to the PHP board, here is a php code for you :slight_smile:

[php]<?php
$dat = “”;
if (isset($_POST[“drop_date”])) {
$dat = strtotime($_POST[“drop_date”]) - 2 * 24 * 60 * 60;
$dat = date(“n/j/Y”, $dat);
}
?>


Drop Date: <input id=“dropdate” name=“drop_date” type=“text” tabindex=“34” value="<?php echo htmlspecialchars($_POST["drop_date"]) ?>" /> Materials Date: [/php]

Thank you for the PHP code. I think I’m going to try it both ways using javascript and your PHP. Its good learning experience.

Adriana

Sponsor our Newsletter | Privacy Policy | Terms of Service