Saturday 13 May 2017

How do i create a get query in nodeJS based on information contained in checkboxes

I am trying to build an app that lets users find other users with a specific combination of skills. I ask the users to select which skills they are looking for via checkboxes but I'm not sure how to request for the status of that checkbox in my function.

My function currently is:

  UserInfo.find()
      .where('skill1').equals('')
      .where('skill2').equals('')
      .where('skill3').equals('')
      .limit(10)
      .then(function(doc) {
        res.render('index', {items: doc});
      });

It works properly if I set the equals('') to true or false but I'm not sure how to set it dynamically. My HTML code for the checkboxes is:

<form action="/getskills" method="get">
        <div class="input">
          <label for="skill1">Skill1</label>
          <input type="checkbox" id="skill1" name="skill1" value="skill1"/>
        </div>
        <div class="input">
          <label for="skill2">Skill2</label>
          <input type="checkbox" id="skill2" name="skill2" value="skill2"/>
        </div>
        <div class="input">
          <label for="skill3">Skill3</label>
          <input type="checkbox" id="skill3" name="skill3" value="skill3"/>
        </div>
  <a href="/getskills">FIND SKILL</a>
    </form>

How can I create and integrate a function to check the value of the checkbox and set the value of the required skill to either true or false?

Thanks in advance for your help.



via chopnfat

No comments:

Post a Comment