Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
change javascript let by html click event
<%- include("partials/header") %>
<p> this is main page</p> 
  
<% let cpp= 6 %>
<%  for (let i=0;i<cpp;i++){ %>
<div class="card">
  <li><%= cards[i].name %></li>
  <li><%= cards[i].price %></li>
  <li><%= cards[i].title %></li>
  <li><%= cards[i].inStore %></li>
  <li><%= cards[i].code %></li>
</div>
<% } %>
<div>button id="next">load more</button></div>

<%- include("partials/footer") %>

how I can change let cpp=6 to cpp=12 on clicking button id="next"

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The array cards must come from the res.render statement in your Javascript file, because there is no let cards.

res.render("ejsfile", {cards: [...]});

So the solution is to put the cpp integer there as well and omit the let cpp = 6 statement:

res.render("ejsfile", {
  cards: [...],
  cpp: Number(req.query.cpp) || 6 // default value
});

Then the first 6 entries would be available at http://server/mainpage?cpp=6 (and also at http://server/mainpage, because 6 is the default value). And the "next" button must link to http://server/mainpage?cpp=12.

See the documentation for req.query.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!