Assign ID to an Javascript button

In my code I have a button for entering data, but as shown in the image below it only reads the first line independent of the button.

Assign ID to an Javascript button

I believe this is because the button id is not being assigned to each row.

How can I get my id from each row to my button?

My ID is ID_Info

     <button class="btn ToEditbtn" ><span class="fa fa-plus-square" aria-hidden="true"></span>Edit</button>
     <button class="btn Editbtn" style="display:none"><span class="fa fa-plus-square-o" aria-hidden="true">Save</span></button>


@section scripts{

    $(function () {
        $("#ordertable").on("click", ".ToEditbtn", function () {
            var currenttr = $(this).closest("tr");
            currenttr.find(".Status").prop("disabled", false);
            currenttr.find(".Obs").prop("disabled", false);
        $("#ordertable").on("click", ".Editbtn", function () {
                var status = new Object();
                status.ID_Info = $(".ID_Info").val();
                status.Status = $(".Status").val();
                status.Obs = $(".Obs").val();





Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

When you click on save button you are getting values using $(".ID_Info") this will not give you required value because there are mutliple class with same name . So, to target only required values you can use $(this).closest('tr').find('valueyouneedtofind').. i.e:

$("#ordertable").on("click", ".Editbtn", function() {
  var status = new Object();
  status.ID_Info = $(this).closest('tr').find(".ID_Info").val();
  status.Status = $(this).closest('tr').find(".Status").val();
  status.Obs = $(this).closest('tr').find(".Obs").val();
  //other codes

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x