0

In a HTML form a date is selected in field with name manufacture_one

When the button is clicked the js function showEndDate() is triggered. The value entered in field with id myTextInputID is assigned to js variable. I have tested that the date entered in the form is displayed in an alert box.

I am trying to assign this variable to php variable and use it as an upper limit in the field with name end_date

      <div>
      <div id="standardPanel">*Task / Person: <input type="text" name="product" required ></div>
      <div id="standardPanel">*Description: <input type="text" name="customer" required ></div>
      <div id="standardPanel">*Date: <input id="myTextInputID" type="date" name="manufacture_one" required ></div>
      <p class="flip" onclick="showEndDate()">Click to add End Date</p>
      <div id="panel">
        End Date: (holidays only) <input type="date" name="end_date" max='<?php echo $endDate; ?>'>
      </div>
      <div><input id="submit" name="action" type="submit" value="submit"/></div>
    </form>

    <script>
    function showEndDate() {
      document.getElementById("panel").style.display = "block";
      var inputValue = document.getElementById("myTextInputID").value;
      alert(inputValue);
      <?php $endDate = "<script>document.write(inputValue)</script>"?> 
    }
    </script>
Jeanclaude
  • 189
  • 1
  • 4
  • 15
  • 1
    Add `document.getElementsByName('end_date')[0].setAttribute("max", inputValue);` to the end of your `showEndDate` function. This sets the `inputValue` as an upper limit for the `end_date` field when the `Click to add End Date` text is clicked. – Marleen Oct 20 '21 at 20:24
  • thank you @Marleen this helped me instantly when i added your answer to my code. – Jeanclaude Oct 20 '21 at 20:34

0 Answers0