I'm learning the basics of node.js and express framework. I have a simple page with two buttons:
<form action="/home2" method="post">
<button name="butt1">butt1</button>
<button name="butt2">butt2</button>
</form>
And i want to see in console which button was pressed:
router.post('/', function(req, res, next) {
console.log(req.body.name);
res.render('home2', { title: 'post' });
});
In the console i just see
undefined
How can I access the name of the button?
I think it would be helpful for you.
<form action="/home2" method="post">
<button name="butt1">butt1</button>
<button name="butt2">butt2</button>
</form>
router.post('/home2', function(req, res, next) {
if(req.body.hasOwnProperty("butt1")){
console.log("butt1 clicked");
}else{
console.log("butt2 clicked");
}
res.render('home2', { title: 'post' });
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With