1

I'm pass a order id with leading-zero to function, but in the function, the parameter alway convert to number without leading-zero,What should I do?

formatter:function(value, row, index) {
    return "<a href='javascript:listGoods("+'09100089'+")'><i class='fa fa-search-plus' /></a>";
                }

function listGoods(id) {
    jp.openViewDialog("goodInfo", "${ctx}/order/order/goods?id=" + id, "800px", "500px");
  }
Legolas
  • 49
  • 6
  • Please provide some more information about what problem you are facing and what is your expected result . – Pushprajsinh Chudasama Sep 11 '19 at 06:59
  • Your question does not give enough information but may be following link solve your problem Why javascript parseInt ignoring leading zeros in the string? https://stackoverflow.com/questions/35238701/why-javascript-parseint-ignoring-leading-zeros-in-the-string/35238742 – Saqib S Sep 11 '19 at 07:00

1 Answers1

0

Your problem is you pass your parameter as a number not as a string. The solution looks like this:

formatter:function(value, row, index) {
    return "<a href='javascript:listGoods(`"+'09100089'+"`)'><i class='fa fa-search-plus' /></a>";
  }

function listGoods(id) {
    jp.openViewDialog("goodInfo", "${ctx}/order/order/goods?id=" + id, "800px", "500px");
  }

Here is another example:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>


<script>
    function addButton() {
        document.body.innerHTML = "<button onclick='showMeParameter(`" + "09100089" + "`)'>my button</button>";
    }

    function showMeParameter(id) {
        alert(id);
    }

    addButton();
</script>
</body>
</html>
Nareen Babu
  • 443
  • 1
  • 5
  • 13
Victor
  • 409
  • 3
  • 14