samedi 3 mars 2018

Check Box in Express JS

If i have a form input like this :

home.ejs

<form action="/route" method="post>
<% for(var i=0; i<5; i++){ %>
<input type="checkbox" name="mytext">
<% }; %>
<input type="submit" value="submit" name="submit">
</form>

router.js

router.post('/route',function (req, res) {
var data = req.body.checkbox;
console.log(data);
});

If i check the [0], [1], [3] :

The Result: [ 'on', 'on', 'on' ]

Expectation: [ 'on', 'on', ' ', 'on', ' ']

Is there any explanation why the result only 3 not 5? and how to fix it? I want to get all the value (checked or not checked).

Thank you




Aucun commentaire:

Enregistrer un commentaire