0

I have this snippet of code:

               <tr id="100" data-row-id="1">        
                                        <td align="center">611000</td>
                                        <td align="center">Regular</td>
                                        <td align="center"><input type="checkbox" name="idc_100" id="idc_100" value="true" data-rowid="1" /></td>   
                                        <td align="center"><input type="text" name="agencybudgetedamount" id="agencybudgeted_100" value="0" data-rowid="1"  disabled/></td>
                                        <td align="center"><input type="text" name="pibudgeted" id="pibudgeted_100" value="0" data-rowid="1"  disabled/></td>                                   
                                        <td align="center"><input type="text" name="PI Adjusted Budget" width="5" id="adjustedBudget_100" data-rowid="1" /></td>
                                        <td class="style1"><input type="text" name="Comments" id="comments_100" size="15" data-rowid="1"  /></td>
                                        <td><button type='button' class="addRegularFac">+</button></td>       
                               </tr>

I can use some slick jquery to get the various properties of each of the inputs I need like the id and the value:

    $('#myTableFac input').each(function (index, input) {
                  alert(input.id + " " + input.name + " " + input.value + " " + input.data("rowid")) ;
                });

(assuming the tr/tds are in a table id myTableFac)

This works well but I want to get those data attributes out as well and I cannot seem to get it using anything I found on stack overflow, leading me to believe the input is a different type of object I am getting. i.e. the .data("item") does not work, tells me function does not exist. So curious what I am doing wrong tried to use this link here:

Retrieving HTML data-attributes using jQuery

Not sure what I am screwing up.

1
  • 2
    Try using $(input).data("rowid") Commented Mar 17, 2016 at 23:03

2 Answers 2

1

Try using $(input).data("rowid")

Fiddle: https://jsfiddle.net/99x50s2s/207/

$('#myTableFac input').each(function (index, input) {
              alert(input.id + " " + input.name + " " + input.value + " " + $(input).data("rowid")) ;
            });
Sign up to request clarification or add additional context in comments.

Comments

0

Try this :

$('#myTableFac input').each(function () {
    console.log($(this).data("rowid")) ;
});

Remove the parameters in your function, and use $(this) to point your input

Comments

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.