0

i want two input in html code and one of them set on form load and other one set on mousedown event when i click on submit button time must be different in each of input problem : but each of inputs have same date and time

test2.php

<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
    <script>
      function SetTimeToEndInput() {
  
        document.getElementById("End").setAttribute("value","<?php date_default_timezone_set('Asia/Tehran'); $t=time(); echo date("Y-m-d h:i:s");?>");
      }
    </script>
  </head>
  <body>

    <form class="" action="test3.php" method="post">
      <input type="text" name="Start" value="<?php date_default_timezone_set('Asia/Tehran'); $t=time();echo date("Y-m-d h:i:s")  ?>">
      <input id="End" type="text" name="End" value="">
      <input type="submit" name="" value="" onmousedown="SetTimeToEndInput()">
    </form>

  </body>
</html>

test3.php


<?php 
  if (isset($_POST['submit'])) {
    echo $_POST['Start'];
    echo $_POST['End'];
    
  }
 ?>

result is '2023-01-27 09:19:04', '2023-01-27 09:19:04'

VOA R
  • 15
  • 6
  • 1
    The code as shown doesn't make sense: there is no element with id "EndInput" for the JS to find, and no function "SetEnd" for the onmousedown event to run. – IMSoP Jan 27 '23 at 07:50
  • Your actual problem though is misunderstanding how PHP and JS can and can't interact. – IMSoP Jan 27 '23 at 08:18
  • i fix some point in question , please help me . yes please show me how php and js can and can't interact – VOA R Jan 27 '23 at 08:38
  • I linked a reference question that explains in depth, but basically *all the PHP runs*, then it gets sent to the browser, and then *all the JS runs*. You can't make PHP code react to something that happens in the browser, because it has already run at that point. – IMSoP Jan 27 '23 at 09:15

0 Answers0