Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

on click event and pass value to function

I have an on click event that calls a function but it does not work:

@foreach (var item in Model.OrderDetails)
{
   <tr class="text-center" id="@item.DetailId">
       <td class="product-remove" onclick="DeleteOrderDetail(@item.DetailId)"><a><span class="ion-ios-close"></span></a></td>
   </tr>
}
@section Scripts
{
    <script>
        function DeleteOrderDetail(orderDetailId) {
            debugger;
            $.get("/Account/RemoveCart?orderDetailId=" + orderDetailId,
                function () {
                    $("#" + orderDetailId).hide('slow');
                });
    </script>
}

error:Uncaught ReferenceError: DeleteOrderDetail is not defined at HTMLTableCellElement.onclick

A search on the internet revealed that I had to use a addEventListener
But in this case, I can not pass the @item.DetailId to the function

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you are making some syntax errors .

you did not close the } of your function .

        function DeleteOrderDetail(orderDetailId) {
        debugger;
        $.get("/Account/RemoveCart?orderDetailId=" + orderDetailId,
            function () {
                $("#" + orderDetailId).hide('slow');
            });
         }

and in this part of your code you should pass data in ''

 <td class="product-remove" onclick="DeleteOrderDetail('@item.DetailId')"><a><span class="ion-ios-close"></span></a></td>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading