I am trying to fetch multi-select values from a form.
JS Code
router.post('/profile', (req, res)=>{
console.log(req.body.name);
})
HTML /profile
<div class="form-group" method="POST">
<br>
<select class="form-control multiselect" multiple="multiple">
{{#team}}
<option value="{{name}}" name="{{name}}">{{name}}</option>
{{/team}}
</select>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">Update Members<i class="icon-circle-right2 ml-2"></i></button>
</div>
</div>
On submitting I am not able to log the body.
There are multiple issues within your code.
name="{{name}}", I assume that variable has a value equal to name[], notice you need to add array brackets to send multiple values for the same key.method="POST" attribute should be added to form tag, not div.In the end, your code should be similar to the code below:
<form method="POST">
<div class="form-group">
<br>
<select class="form-control multiselect" multiple="multiple" name="name[]">
{{#team}}
<option value="{{name}}" >{{name}}</option>
{{/team}}
</select>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">Update Members<i class="icon-circle-right2 ml-2"></i></button>
</div>
</div>
</form>