Solution 1 :

With javascript you’ll have to use something like this:

  var date_arrival = document.getElementsByName('date_arrival')[0];
  var date_leave = document.getElementsByName('date_leave')[0];

  date_arrival.addEventListener('change', function() {
    date_leave.value = date_arrival.value;

Problem :

I am creating a form using html and php, inside this form I have date input “from” and date input “to”.
How can “to” get update with the date I select in “from”?
For example, if I select in the “from” July 1st, I want “to” to get update with the same date or the next day.

This is my form:

<?php ob_start() ?>
<?php if(isset($params['message'])) :?>
    <b><span style="color: red;"><?php echo $params['message'] ?></span></b>
<?php endif; ?>
<form name="formInsertDocument" action="index.php?ctl=insertDocument" autocomplete="off" method="POST">
    <h2>Insert New Document</h2>
                <label for="name">Type:</label>
                <input type="number" name="id_type" required value="<?php echo $params['id_type'] ?>" />
                <label for="name">Client:</label>
                <input type="number" name="id_client" required value="<?php echo $params['id_client'] ?>" />
                <label for="name">Date:</label>
                <input type="date" name="date_document" required value="<?php echo date('Y-m-d'); ?>" value="<?php echo $params['date_document'] ?>" />
                <label for="name">Arrival:</label>
                <input type="date" name="date_arrival" required value="<?php echo date('Y-m-d'); ?>" value="<?php echo $params['date_arrival'] ?>" />
                <label for="name">Departure:</label>
                <input type="date" name="date_leaving" required value="<?php echo date('Y-m-d'); ?>" value="<?php echo $params['date_leaving'] ?>" />
                <label for="name">Subtotal:</label>
                <input type="number" name="subtotal" required value="<?php echo $params['subtotal'] ?>" />
                <label for="name">Taxable:</label>
                <input type="number" name="taxable" required value=00000000 value="<?php echo $params['taxable'] ?>" />
                <label for="name">Tax:</label>
                <input type="number" name="tax" value=00000000 value="<?php echo $params['tax'] ?>" />
                <label for="name">Other:</label>
                <input type="number" name="other" required value="<?php echo $params['other'] ?>" />
                <label for="name">Total:</label>
                <input type="number" name="total" required value=0 value="<?php echo $params['total'] ?>" />
    <input type="submit" value="Insert" name="insert" />
<?php $contenido = ob_get_clean() ?>
<?php include '../app/templates/layout.php' ?>


Comment posted by izambl

Do you want to a pure php solution? if not it’s easily done with javascript

Comment posted by mejia_david

php will be the go to but, I guess I can a JS part

Comment posted by misorude

Why are you putting

Comment posted by mejia_david

I have two values because I have yet to validate the data that goes into the db, if I sent blanks, it wont add to db. for now