Search code examples
phpajaxzero

How to fix Ajax post Removing front zero


I have a code that passing the value from 1 page to another page which is modal.

I tried to document.write the passed value but it returns with no 0

First Page

<button onclick="openmodalseparationpay(<?=$row['EmpNo']?>)" title="Separation" ></button>

The Value here in fist page is 0003 and it comes from database

Second Page

function openmodalseparationpay(x){
$.ajax({
type:"POST",
url:"payroll_window_ajax.php",
data:{input:'openmodalseparationpay',empid:x},
success: function(data){
$('#separationpay'+x).modal('show');
$('#separationmodalbody'+x).html(data);
}});}

But here in Second page it returns as 3

I expect the output of 3 to be 0003.


Solution

  • Looks like you are passing value as integer, you need to pass it as string to preserve zeros. Please try following:

    <button onclick="openmodalseparationpay('<?=$row['EmpNo']?>')" title="Separation" ></button>