Problem with html templating using express

56 Views Asked by At

Hey guys i have a problem with EJS and express for changing my html file I am trying to get user data through a form in html like this:-

<form action="/" method="post">
 <input type="text" placeholder="Your new task" name="newTask">
 <button type="submit">Add</button>
</form>

This form sends back the data to the home route or (the root) so i am trying to get the day in the server using :-

app.post("/",(req,res)=>{
    var task = req.body.newTask;
    tasks.push(task);
    res.redirect("/");
});

And then this data i am pushing it to a array called tasks and that task using EJS features i am sending it back to the html file through this :-

   res.render("list",{
        kindOfDay:dayOfWeek,
        addedTasks:tasks,
    });

And the above code sends this data to the html file and the data is rendered in html like this :-

<h1><%=kindOfDay%></h1>
<ul>
    <li>Buy food</li>
    <li>Cook food</li>
    <li>Eat food</li>
  <% for(var i=0; i<addedTasks.lenght ; i++) { %>
      <li><%= addedTasks[i] %></li>
 <% } %>
</ul>

Everything is working fine expect 'addedTasks'. If i type in something it is not getting displayed,Thank you.

1

There are 1 best solutions below

0
On

Write addedTasks.length instead of addedTask.lenght in your last code snippet.