title: How to pass div value to php
body: <p>I need to pass value of the div with <code>id="monthlyPayment"</code>, that takes value after filling the inputs and calculations on js-side, to php and send it to email. I was trying to do it with AJAX and DOM but I have a little experience so it did not work out, maybe someone can help me!</p>
  
  <pre class="lang-js prettyprint-override"><code>function credit() {
      var loanTerm = document.getElementById('loanTerm').value * 12;
      var interestRate = 0.09858333;
      var creditSum = document.getElementById('carPrice').value - document.getElementById('anInitialFee').value;
  
      var monthlyPayment = (parseFloat(creditSum) * parseFloat(interestRate) / (1 - Math.pow(1 + parseFloat(interestRate), -loanTerm))).toFixed(2);
  
      document.getElementById('monthlyPayment').innerHTML = "Ваш ежемесячный платеж: " + monthlyPayment;
      document.getElementById('sent').style.visibility = "visible";
  }
  </code></pre>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
      &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;script src="functions.js"&gt;&lt;/script&gt;
          &lt;script src="jquery-3.2.1.slim.js"&gt;&lt;/script&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;form action="mail_sender.php" method="post"&gt;
          &lt;input type="text" id="firstName" name="firstName" value="" placeholder="укажите ваше имя"&gt;&lt;br&gt;
          &lt;input type="email" id="email" name="email" value="" placeholder="укажите ваш email"&gt;&lt;br&gt;
          &lt;input type="tel" id="phone" name="phone" value="" placeholder="укажите ваш телефон"&gt;&lt;br&gt;
          &lt;input type="text" id="carPrice" name="carPrice" value="" placeholder="укажите цену автомобиля"&gt;&lt;br&gt;
          &lt;input type="text" id="anInitialFee" name="anInitialFee" value="" placeholder="укажите первоначальный взнос"&gt;&lt;br&gt;
          &lt;input type="text" id="loanTerm" name="loanTerm" value="" placeholder="укажите срок кредита"&gt;&lt;br&gt;
          &lt;div id="monthlyPayment"&gt;&lt;/div&gt;
          &lt;button id="sent" style="visibility:hidden;"&gt;Send to email?&lt;/button&gt;
      &lt;/form&gt;
      &lt;button id="credit" onClick="credit();"&gt;Calculate&lt;/button&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
      $recipient = $_POST['email'];
      $subject = "Письмо с сайта";
      $name = $_POST['firstName'];
      $email = $_POST['email'];
      $phone = $_POST['phone'];
      $carPrice = $_POST['carPrice'];
      $anInitialFee = $_POST['anInitialFee'];
      $loanTerm = $_POST['loanTerm'];
      $monthlyPayment = $_POST['monthlyPayment'];
      $mailBody = "Имя: $name \n Email: $email \n Телефон: $phone \n Цена автомобиля: $carPrice \n Первоначальный взнос: $anInitialFee \n Срок кредита: $loanTerm \n Ежемесячный платеж: ";
      mail($recipient, $subject, $mailBody);
      echo "Mail sent.";
  ?&gt;
  </code></pre>