1

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
  • you have a typo length not lenght Commented Dec 11, 2020 at 8:47

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.