Solution 1 :

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

<script>
  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;
  });
</script>

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; ?>
<?php
    date_default_timezone_set('America/Costa_Rica');
?>
<br/>
<form name="formInsertDocument" action="index.php?ctl=insertDocument" autocomplete="off" method="POST">
    <h2>Insert New Document</h2>
    <fieldset>
        <ul>
            <li>
                <label for="name">Type:</label>
                <input type="number" name="id_type" required value="<?php echo $params['id_type'] ?>" />
            </li>
            <li>
                <label for="name">Client:</label>
                <input type="number" name="id_client" required value="<?php echo $params['id_client'] ?>" />
            </li>
            <li>
                <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'] ?>" />
            </li>
            <li>
                <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'] ?>" />
            </li>
            <li>
                <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'] ?>" />
            </li>
            <li>
                <label for="name">Subtotal:</label>
                <input type="number" name="subtotal" required value="<?php echo $params['subtotal'] ?>" />
            </li>
            <li>
                <label for="name">Taxable:</label>
                <input type="number" name="taxable" required value=00000000 value="<?php echo $params['taxable'] ?>" />
            </li>
            <li>
                <label for="name">Tax:</label>
                <input type="number" name="tax" value=00000000 value="<?php echo $params['tax'] ?>" />
            </li>
            <li>
                <label for="name">Other:</label>
                <input type="number" name="other" required value="<?php echo $params['other'] ?>" />
            </li>
            <li>
                <label for="name">Total:</label>
                <input type="number" name="total" required value=0 value="<?php echo $params['total'] ?>" />
            </li>
        </ul>
    </fieldset>
    <input type="submit" value="Insert" name="insert" />
</form>
<?php $contenido = ob_get_clean() ?>
<?php include '../app/templates/layout.php' ?>

Comments

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

By