mercredi 23 mars 2016

Submit value of checked checkbox to express

I have a small form with three checkboxes. Only one checkbox can be selected by the user. I need to return the value of this checkbox back to the server, however the function I am using to make only one checkbox select-able at a time relies on the name of the checkboxes to all be the same. The conditional logic would flow:

if checkbox is checked send only this data to express

However, how do I pick that up on the express side of things? My code so far:

Template - Jade

  .form-group
    label When is it?
    label
      input(type='checkbox' name='group1[]' value='week')
      span This week
    label
      input(type='checkbox' name='group1[]' value='month')
      span This Month
    label
      input(type='checkbox' name='group1[]' value='date')
      span Date

Checkbox selector - JS

$('input[type="checkbox"]').on('change', function() {
    $('input[name="' + this.name + '"]').not(this).prop('checked', false);
});

Express

router.get('/', function(req, res, next) {
  var url = req.body.search;
  var title = req.body.title;
  var week = req.body.group1[];
  var month = req.body.group1[];
  var date = req.body.group1[];
});




Aucun commentaire:

Enregistrer un commentaire