1

I am trying to access the td element from a table,based on selected id via check boxes, the idea is that I check multiple check boxes and then from the value="@item.id" I use the value to check for their tr and then finally access the td. What I want is to get the Status so that I can do a dialog message pop up. Status is the 5th td in the table row.

Not sure if this is a good design to go about it.

I have tried something with this How to get a table cell value using jQuery? but I am not getting the correct values, it outputs something like "< alot of spaces ....> Approved".

e.g. use case: Annual Leaves has been approved/rejected, user selected some approved leaves and tries to approve and then a warning modal pop up will prompt user to that "Cannot approve approved leaves or reject rejected leaves again". Below is my original script without the stuff from the url.

@foreach (var item in Model)
{
    <tr>
        <td align="center">
                <input type="checkbox" name="chkSelectAll" id="chkSelectAll" value="@item.Id"/>
            </td>
            <td align="center">
                @Html.DisplayFor(modelItem => item.UserId)
            </td>
            <td align="center">
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td align="center">
                @Html.DisplayFor(modelItem => item.StartDate)
            </td>
            <td align="center">
                @Html.DisplayFor(modelItem => item.StartSlot)
            </td>
            <td align="center">
                @Html.DisplayFor(modelItem => item.Status)
            </td>
    </tr>
}

<script>
        function multiSelect(selectedArray, action)
        {
            if (selectedArray[0] === undefined) {
                $.fn.bootstrapBtn = $.fn.button.noConflict();

                $(function () {
                    $("#dialog-warning").dialog({
                        modal: true,
                        buttons: {
                            Ok: function () {
                                $(this).dialog("close");
                            }
                        }
                    });
                });
            }
        }
</script>
DatB
  • 51
  • 6
  • 1
    you should try this function for get the id `function getElementsById(ids) { var idList = ids.split(" "); var results = [], item; for (var i = 0; i < idList.length; i++) { item = document.getElementById(idList[i]); if (item) { results.push(item); } } return(results); } doStuff(getElementsById("id1 id2 id3 id4"));` remember to type space between id s. – Aashif Ahamed Dec 26 '19 at 07:14
  • will try it when i have access to the files! – DatB Dec 29 '19 at 10:44
  • good luck. it to be sucess – Aashif Ahamed Dec 30 '19 at 07:45

0 Answers0