title: multiple option boxes same name jquery ajax
body: <p>I've got multiple select boxes that have the same name. Right now when I select the value from the first select box its submitting that one and updating the database. When I select and item on an other select box its submitting the value from the first one. I feel like the javascript isn't right. Any idea what is wrong?</p>
  
  <p>Heres my html:</p>
  
  <pre><code>&lt;?php foreach ($result as $row): ?&gt;
  &lt;select class="form-control" name="category[]" required&gt;
      &lt;option value="" disabled selected&gt;Select The Category &lt;/option&gt;
      &lt;option value="station"&gt;Station&lt;/option&gt;
      &lt;option value="equipment"&gt;Tools/Equipment&lt;/option&gt;
      &lt;option value="supplies"&gt;Supplies&lt;/option&gt;
  &lt;/select&gt;
  &lt;input id="taskID" value="&lt;?php echo $row['id']; ?&gt;" hidden&gt;&lt;/input&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <p>jquery:</p>
  
  <pre><code>$(document).on('change', 'select[name="category[]"]', function(event){
    $('select[name="category[]"]').each(function(){
            var formData = {
                'task': $('select[name="category[]"]').val(),
                'name': $('input[name="taskID[]"]').val(),
            };
            $.ajax({
                    type: 'POST',
                    url: 'php/addressBook.php',
                    data: formData,
                    dataType: 'html',
                    encode: true
                })
                .done(function(msg) {
                    $(".alert").html(msg);
                })  
                .fail(function(data) {
                    console.log(data);
                })
            event.preventDefault();
        });
    });
  </code></pre>
  
  <p>addressBook.php</p>
  
  <pre><code>if (isset($_POST['task'])) {
  
    $task = $_POST['task'];
    $id = $_POST['name'];
  
    $stmt = $con-&gt;prepare("UPDATE members SET task = ? WHERE id = ?");
    $stmt-&gt;bind_param('ss', $task, $id);
    $stmt-&gt;execute();
  
  }
  </code></pre>