0

HTML:

<button type="button" value="" onclick="getInfo(007267, 10140000000)" class="btn btn-xs btn-primary">INFO</button>

JavaScript:

function getInfo(growerid, plantid) {
  $.ajax({
    type: "POST",
    url: "plantsearch.php",
    data: "op=" + "info" + "&gid=" + growerid + "&pid=" + plantid + "&ml=" + MyLimit + "&mo=" + MyOffset,
    datatype: "text",
    success: function (data, status, xhr) {
      //$("#tbody_info").html(data);
      alert(data);
    },
    error: function (xhr, status, error) {
      alert(status);
    }
  });
}

The problem is the growerid is correct in the HTML, i.e. 007267, however, when the function is called the value of growerid is not 007267 but 3767. Why is this changing?

Thanks, TD

Joshua
  • 3,055
  • 3
  • 22
  • 37
DLee
  • 73
  • 1
  • 6
  • 2
    Try using a string instead ~ `getInfo('007267', 10140000000)`. While you're there, I highly recommend setting `data` as an object instead of a string. jQuery will encode the values correctly then ~ `data: {op: 'info', gid: growerid, pid: plantid, ml: MyLimit, mo: MyOffset}` – Phil Apr 30 '18 at 00:45
  • I did not know that the string was being treated as an octal because it has a leading 0, so I learned something there. The answer for me was to wrap both parameters for the function in single quotes like this: onclick="getInfo()" – DLee Apr 30 '18 at 19:14

0 Answers0