2

I can not get the value for the hidden input element from this table.

Here is my table:

<table id="scrapApprovalTable" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th></th>
            <th>Date</th>
            <th>Company</th>
            <th>Notes</th>
            <th>Comments</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <cfoutput>
            <cfloop query="GetRequests">
                <tr class="#specialPricingScrapID#" id="#specialPricingScrapID#">
                    <td class="details-control" value="#specialPricingScrapID#"></td>
                    <td class="date">#DateFormat('#enterDate#', 'mm-dd-yyyy')#</td>
                    <td class="company"><a href="http://www.pblead.com/cfleadsource/MarMgt.cfm?ContactID=#contactid###ContactInfo" target="_blank">#company#</a>
                    </td>
                    <td class="notes">#notes#</td>
                    <td class="comments">
                        <textarea name="processingScrapComments-<cfoutput>#specialPricingScrapID#</cfoutput>" id="processingScrapComments-<cfoutput>#specialPricingScrapID#</cfoutput>" cols="30" rows="5"></textarea>
                    </td>
                    <td class="buttons">
                        <input type="hidden" id="requestID" value="#specialPricingScrapID#">
                        <button class="btn btn-success btn-block btn-small" id="btn-ApproveScrapRequest" name="btn-ApproveScrap" onclick="processRequest(#specialPricingScrapID#, #contactid#, #userid#)">Approve</button>
                        <br>
                        <button class="btn btn-danger btn-block" id="btn-RejectScrapRequest" name="btn-RejectScrap" onclick="processDenial(#specialPricingScrapID#, #contactid#, #userid#)">Deny</button>
                        <br>
                    </td>
                </tr>
            </cfloop>
        </cfoutput>
    </tbody>
</table>

Here is my javascript I am using:

$(document).ready(function () {
    var approvalTable = $('#scrapApprovalTable').DataTable();
    $('#scrapApprovalTable tbody').on('click', 'td.details-control', function (e) {
        e.stopPropagation();
        var $this = $(this);
        var trid = $this.closest('tr').data('id');
        alert("TR ID " + trid);
        var tdid = $this.find('td[data-id]').data('id');
        alert("TD ID " + tdid);
    });
});

I am just wanting to get the value of

  1. the hidden element
  2. or the ID of the TR selected or
  3. the value of the class="details-control' for the row selected.

all of which are the same value. What I am trying to accomplish is to get the value so that I can do another request.

thanks for everyone's help.

This table is loaded directly on creation.

2 Answers 2

2

Use the code below to get the value of id attribute of <tr> element:

$(this).closest('tr').attr('id');
Sign up to request clarification or add additional context in comments.

Comments

1

DEMO

var approvalTable = $('#scrapApprovalTable').DataTable();
$('#scrapApprovalTable tbody').on('click', 'td.details-control', function (e) {
    e.stopPropagation();
    var $this = $(this);
    var trid = $this.closest('tr').attr('id');
    alert("TR ID " + trid);
    var tdid = $this.find('td#' + trid).attr('id');
    alert("TD ID " + tdid);
});

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.