1

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.

img

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

 <td>
     <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>

 </td>

@section scripts{
<script>

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

         ...

         <script>
         }

Thanks

1

1 Answer 1

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
})
Sign up to request clarification or add additional context in comments.

2 Comments

that's right, thanks, by the way since i'm receiving the data can you help me save? because I use db.savechanges but it doesn't record
Hi , i would helped but , i have limited knowledge in asp :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.