Reputation: 1095
I have an input tag of type text. I want to access the value of input tag whenever user enter and push it to the json.
my jade file looks like,
extends layout
block content
h1 todos
#task
<input type="text" id="task" name="task"/>
#todos
for todo in todos
include todo
I am writing access code using express,
app.get('/', function(req,res){
todos.push(new todo(req.bodyParser.task))
res.render('index',{todos:todos});
});
I am beginner to javascript,node and jade as well.
Upvotes: 1
Views: 705
Reputation: 557
Use form to submit your data to server:
block content
h1 todos
form(action="/todos", method="post", id="taskform")
input(type="text", name="task")
#todos
for todo in todos
include todo
In node, now you can access task
using req.body.task
:
app.post('/todos', function(req,res){
todos.push(new todo(req.body.task))
res.render('index',{todos:todos});
});
Upvotes: 1