How do I pass a variable to inline javascript using EJS templating engine?

I've created a html list of buttons/text from an array called items in an .EJS template. How do I pass the specific item's id ( to the button's function so I can send the right data to my api? Thanks.

<!DOCTYPE html>
<html lang="en">
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">

    function print(id) {
          url: "",
          type: "POST",
          data: {
            "item_id": id
          dataType: "json",
          success: function (result) {
          error: function (xhr, ajaxOptions, thrownError) {
        <% for(item of items) { %>
            <button onclick="print(">PRINT</button>
            <%= %> - <%= %>
        <% } %>


<button onclick="print('<%= %>')">PRINT</button>

is how you would do it in every templating language I have used. After looking at the docs, it appears EJS is the same


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.