javascript - Pass variable to .txt file -


i trying pass variable html form .php script , .php script .txt file variable value stored. problem is, when test scripts instead of posting variable number posts variable name "numbervariable".

html/javascript

    <form id="payment-form" action="chargecard.php" method="post" name="payment-form">                             <input onkeypress="return isnumberkey(event)" type="text" name="amount" id="amount" />                             <input type="hidden" id="numbervariable" name="numbervariable" value="numbervariable"/> <!--this try pass variable .php script-->                             <input type="image"  src="button1.png" id="custombutton" value="pay" alt="button"/>                              </form>      <script type="text/javascript">                             function isnumberkey(evt)                         {                         var charcode = (evt.which) ? evt.which : event.keycode                         if (charcode > 31 && (charcode < 48 || charcode > 57))                         return false;                          return true;                         }                         </script>  <script type="text/javascript">                               var numbervariable= 1; //this variable trying pass .php script pass value .txt file                              document.getelementbyid("numbervariable").innerhtml = numbervariable;                             document.getelementbyid("numbervariable").value = numbervariable;                          </script> 

php

<?php       require_once('./stripe-php/init.php');      \stripe\stripe::setapikey("removed safety");      $token = $_post['stripetoken'];     $myamount = $_post['amount'];     $describtion = $_post['description'];      $numbervariable= $_post['numbervariable']; //this variable form      $myamount = round((int)$myamount*100,0);      try {     $charge = \stripe\charge::create(array(     "amount" => $myamount,     "currency" => "usd",     "source" => $token,     "description" => $describtion));      //paste variable .txt file start      $filename = "iphoneauctionbids.txt";     $content = file_get_contents($filename);     $content .= $numbervariable. php_eol;     file_put_contents($filename, $content);      //paste variable .txt file end      } catch(\stripe\error\card $e) {     }  ?> 

you don't file.

you need open file , write value it.

$filename = "iphoneauctionbids.txt";  $content = file_get_contents($filename); $content .= $numbervariable . php_eol; file_put_contents($filename, $content); 

also might want wait html generated before js processing on dom. put js code inside

window.onload(function(){ // here }); 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -