mardi 17 mars 2015

Proper way to read checkbox data in NodeJS

I have a form on my webpage and its being submitted to a NodeJS backend.'


I'm having trouble with the checkboxes. When the are submitted to server, and I read them via req.body.foods, I get something like ['on', 'on', 'on'].


But I want to get the actual values, that is, something like ['dairy', 'fish'] etc.


How can I do that?



<div class="col-sm-6">
<div class="checkbox">
<label><input name="food" type="checkbox" value="dairy">Dairy</label>
</div>
<div class="checkbox">
<label><input name="food" type="checkbox" value="meat">Meat</label>
</div>
<div class="checkbox">
<label><input name="food" type="checkbox" value="fish">Fish</label>
</div>
</div>




Aucun commentaire:

Enregistrer un commentaire