SO i am trying to change the value of an html tag in an ejs file to a variable i declared in a JavaScript file
let checkbox = document.querySelector('input[name="plan"]'); checkbox.addEventListener('change', function () { if (this.checked) { document.querySelector('.plan-title').innerHTML = investment.name; document.querySelector('.plan-description').innerHTML = investment.description; } else { document.querySelector('.plan-title').innerHTML = ''; document.querySelector('.plan-description').innerHTML = ''; } });
So when I pass it directly it shows but I want it to be dynamic and Although it gets pass through when i click the checkbox it doesn't seem to have any value.
<%- include('../partials/sidebar'); %> <% if(currentUser && currentUser.isAdmin){ %> <a href="/investment/new">Add New Plan</a> <% } %> <div class="container"> <h1>Investments</h1> <% investments.forEach((investment)=>{ %> <div class="col-md-4"> <div class="card"> <strong> <%= investment.name %> </strong> <h4> <%= investment.min %> - <%=investment.max %> </h4> <p> <%= investment.caption %> </p> <p><input type="checkbox" name="plan" id="">Choose investment</p> </div> <% if(currentUser && currentUser.isAdmin){ %> <a href="/investment/<%= investment._id %>/edit">Edit</a> <a href="/investment/new">Delete</a> <% } %> </div> <% }) %> <% investments.forEach((investment)=>{ %> <div class=""> <div><strong>Package: </strong> <p class="plan-title"> </p> </div> <p class="plan-description"> </p> <input type="number" name="" id="" min="<%= investment.min %>" max="<%= investment.max %>"> </div> <% }) %> </div> <%- include('../partials/footer'); %>
I cant seem to get through this, need help thanks!
from Recent Questions - Stack Overflow https://stackoverflow.com/questions/65376944/how-to-use-a-passed-variable-in-an-ejs-file simon
没有评论:
发表评论