Home » Jquery » javascript – How can we pass floating point values input type to another page to retrieve

javascript – How can we pass floating point values input type to another page to retrieve

Posted by: admin February 22, 2020 Leave a comment

Questions:

How can we pass floating point values to another page? I have sent a floating point value in an AJAX request, but the page only received an integer value.

<div class="form-group">
  <label for="" class="col-sm-4 control-label">Pole to Pole distance in feets <font color="red">*</font></label>
  <div class="col-sm-6">
    <input type='number' class="form-control" name='ppdistance' id="ppdistance" placeholder="Pole to Pole distance in feets" required="required" min="0">
  </div>
</div>
<br>
<div class="form-group">
  <label for="" class="col-sm-4 control-label">Number of Fencing line per Pole <font color="red">*</font></label>
  <div class="col-sm-6">
    <input type="number" class="form-control" name='fensing' id="fensing" placeholder="Number of Fencing line per pole " required="" step="0.01">
  </div>
</div>
<br>
<div class="modal-footer">
  <input type='button' id="myBtn" class="btn btn-default btn1" value="Submit">
</div>
document.getElementById("myBtn").addEventListener("click", myFunction);

function myFunction() {
  let data = {
    size: $('[name="size"]').val(),
    numpols: $('[name="numpols"]').val(),
    ppdistance: $('[name="ppdistance"]').val(),
    fensing: $('[name="fensing"]').val()
  }
  alert(data);

  $.ajax({
    type: "POST",
    url: "joins.php", //"join.php"
    dataType: "html",
    data: data,
    success: function(response) {
      document.getElementById('demo').innerHTML = response;
    },
    error: function(error) {
      alert(error)
    }
  });

Retrieve Page values can print integer values display

echo $numpols;
echo '<br>';
echo $ppdistance;
echo '<br>';
echo $fensing;
echo '<br>';

echo $ms = $numpols * $ppdistance * $fensing;

The output I get looks like this:

670
7
78
365820

I am expecting my output to look like this:

670
7
7.8
36582

How can I fix this?
can u see the screen shot also please find the attachment for floating value

How to&Answer:

use parseFloat on jquery

fensing: parseFloat($('[name="fensing"]').val())