title: How to set a php variable inside a javascript function?
body: <p>I want to create an OTP sender and checker.<br>
  The code is like this:<br></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
   $Mail = "someone@gmail.com";
    $OTP = mt_rand();
    $subject = "OTP from HelloBuddy.co.in";
    $txt = "You have recieved OTP from HelloBuddy.co.in. The OTP is $OTP. Please enter the OTP in the website. Please note that the OTP will expire in 100 seconds.";
      if (mail($Mail,$subject,$txt)){
     echo "&lt;p&gt;OTP has been successfully sent&lt;br&gt;The OTP will expire in &lt;span id='xpire'&gt;100&lt;/span&gt; seconds.&lt;br&gt;Please enter the OTP here:&lt;input type='number' name ='OTP'&gt;&lt;/p&gt;";
     echo "&lt;script&gt;
       var a = 99;
       var x = setInterval(cdown, 1000);
       function cdown(){
        if (a&gt;=0) {
         document.getElementById('xpire').innerHTML = a;
         a=a-1;
        } else {
         clearInterval(x);
         clearOTP()
        }
       function clearOTP{
       $OTP = '';
            }
            &lt;/script&gt;";
      }else{
     die(ERROR);
  }
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am using xampp server and have correctly configured the required files.<br>
  I want to clear the OTP after 100 seconds, but cant, perhaps because it is inside a javscript function.<br>
  If possible, give an AJAX.</p>