How to get values from specified table rows in Meteor.js

In my Meteor app, I have the following table which shows some info. Users can edit company name, address and email and save the changes by clicking the button beside.

  <table class="table table-hover">
      <th>Company Name</th>
      <th>Company Address</th>
      <th>Email Address</th>
      <th>Last Login</th>
    {{#each users}}
    <td><input type="text" name="companyName" value="{{companyName}}"></td>
    <td><input type="text" name="companyAddress" value="{{companyAddress}}"></td>
    <td><input type="text" name="companyEmail" value="{{}}"></td>
    <td><input type="submit" class="btn btn-primary save" value="Save">
    <input type="submit" class="btn btn-danger delete" value="Delete"></td>

In event handler:

  'click .save':function(e,inst){
    var userID = this._id;
    var companyName = inst.$('[name=companyName]').val();
    var companyAddress = inst.$('[name=companyAddress]').val();
    var companyEmail = inst.$('[name=companyEmail]').val();

By doing so, It only can read the values of the first row of table. Then I add data-id in input field <td><input type="text" name="companyName" value="{{companyName}}" data-id="{{_id}}"></td> It is able to get company name from the table row. My question is how to do with the rest of attributes.

The problem is you’re creating multiple <input name="attributeName" /> elements and then getting the closest element’s value with inst.$('[name=attributeName]').val(). You need to either put each table row in a separate template that will allow you to get the value in scope of the row using inst.$('[name=attributeName]').val(), or you can assign each input element the data-id="{{_id}}" attribute and get the value by selecting the input element using inst.$('[name=attributeName]'+'[data-id="' + this._id + '"]').val();

Thank you so much! Now I know where the problem is.