Fahad Almehaini Fahad Almehaini - 1 month ago 12
Javascript Question

javascript jquery is removing the decimal point and zero

I am doing plus minus with plus minus button but when i do it js removes the decimal point and zero's

12.000
after doing plus minus it shows
12
only and i want to keep the decimal point and zero like
12.000
.

Here is the
SPAN
where the result is showing:

<span id="product1_total_<?php echo $prITTD; ?>">
</span>


How can i fix this issue in my js below:

function subtractQty(prITTD){
var pr = document.getElementById("number_" + prITTD);
if (pr.value - 1 < 1)
return;
else
pr.value--;
}


$(document).ready(function() {
$(".operator").on('click',function() {
$("#product1_total_<?php echo $prITTD; ?>").text($("#product1_base_<?php echo $prITTD; ?>").val() * $("#number_<?php echo $prITTD; ?>").val());
});
});

Answer

This query had to be fixed as in the discussion under the answer of Vural Acar i said that we need to merge the queries.

The below fix solved my problem, actually it has to be fixed. Because this is the result div and the problem was in the result div.

($("#product1_base_<?php echo $prITTD; ?>").val() * $("#number_<?php echo $prITTD; ?>").val()).toFixed(3)

The above is the fix in the below query to keep the decimals inspired from Vural Acar Answer.

$(document).ready(function() {
  $(".operator").on('click',function() {
      $("#product1_total_<?php echo $prITTD; ?>").text(($("#product1_base_<?php echo $prITTD; ?>").val() * $("#number_<?php echo $prITTD; ?>").val()).toFixed(3));
  });
});

The below query is for plus minus button only to do plus minus for the quantity.

function subtractQty(prITTD){
  var pr = document.getElementById("number_" + prITTD);
  if (pr.value - 1 < 1)
    return;
  else
    pr.value--;
}
Comments