title: Retrieving value from input in EJS with NodeJS
body: <p>Here is my EJS code:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form action="/" method="POST"&gt;
              &lt;% items.forEach((item)=&gt;{ %&gt;
              &lt;div class="item"&gt;
                  &lt;input type="checkbox" name="checkbox" value="&lt;%=item._id%&gt;" onchange="this.form.submit()"&gt;
                  &lt;p&gt;&lt;%= item.name %&gt;&lt;/p&gt;
              &lt;/div&gt;
              &lt;% }) %&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>And here is the app.js:</p>
  
  <pre><code>app.post('/',(req,res)=&gt;{
      console.log(req.body.checkbox);
  })
  </code></pre>
  
  <p>My questions are:</p>
  
  <p>1) Why does it only log the value of the selected checkbox (assumed that there are 3 items) instead of 3 values, is it because of the post method only post the checkbox's value that has the property <code>checked</code> == true?</p>
  
  <p>2) If I add another checkbox like below, why does it return <em>undefined</em> if I try to <code>console.log(req.body.item_id)</code>?</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form action="/" method="POST"&gt;
              &lt;% items.forEach((item)=&gt;{ %&gt;
              &lt;div class="item"&gt;
                  &lt;input type="checkbox" name="checkbox" value="&lt;%=item._id%&gt;" onchange="this.form.submit()"&gt;
                  &lt;p&gt;&lt;%= item.name %&gt;&lt;/p&gt;
                  &lt;input type="checkbox" name="item_id" value="&lt;%=item._id%&gt;"&gt;
              &lt;/div&gt;
              &lt;% }) %&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>3) I've tried to do the same thing above but this time it is using <code>input</code> type of <code>text</code>. Why does the <code>console.log(req.body.item_id)</code> show 3 values instead of 1 (which corresponds with the selected checkbox like in question 1)?</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form action="/" method="POST"&gt;
              &lt;% items.forEach((item)=&gt;{ %&gt;
              &lt;div class="item"&gt;
                  &lt;input type="checkbox" name="checkbox" value="&lt;%=item._id%&gt;" onchange="this.form.submit()"&gt;
                  &lt;p&gt;&lt;%= item.name %&gt;&lt;/p&gt;
                  &lt;input name="item_id" value="&lt;%=item._id%&gt;"&gt;
              &lt;/div&gt;
              &lt;% }) %&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>All response are appreciated. Thank you!</strong></p>