I have dynamically generated as given below.I need to get the value of text box by clicking on the updateCart button in each row.

 @foreach (var item in Session["Cart"] as List<AP.WebApp.Models.Cart>)
                    {
                    <tr class="eachitem">
                        <td><img src="@item.Path.Split('~')[1]" style="width:200px;height:auto" /><p>@item.Title</p></td>
                         <td>
                        @if(item.Preview == 1){

                            @Html.CheckBox("preview", new { @checked = "checked" })
                        }
                        else
                        {
                             @Html.CheckBox("preview")
                        }
                             </td>
                        <td id="qtyid">
                            <input id="qty" type="text"  value="1"/></td>
                        <td>0</td>
                        <td>
                            <input id="deleteCart" type="submit" value="Delete" data-assigned-id="@item.ID" /></td>
                        <td>
                            <input id="updateCart" type="submit" value="Update" data-assigned-id="@item.ID"  /></td>

                    </tr>
                    }

For that I tried :

 $('.cartItem').on('click', '#updateCart', function (e) {
            e.preventDefault();
var val = $(this).closest('#qtyid').find('#qty').val();
});

But alert(val) results undefined.Any idea please share.

Related posts

Recent Viewed