MvcGrid Checkbox with Textbox not showing the right textbox value

156 Views Asked by At

I had a scenario:

My MVCGrid View Image:

enter image description here

This my Html Javascript Code:

 $('#btn_preview_').click(function(){
            Validate()
        });

        function Validate()
        {

            $('.mvcGrid table tr').each(function () {
                if($('.mvcGrid table tr input[name=MyCheckbox]:checkbox').is(':checked')==true)
                {
                    var getText =   $.trim($('.mvcGrid table tr td:eq(2) input[name=textboxRemarks]').val());

                    alert('SID ' + $(this).find('td:eq(1)').text() +  ' getText ' + getText);
                }
                else
                {
                    Alert('Checkbox is unchecked');
                }
            });
        }

Addtional html code:

<div class="mvcGrid rowMarginTop">
               @Html.Grid(Model.myData).Columns(columns =>
               {

                   columns.Add(a => a.isF).Encoded(false).Sanitized(false).RenderValueAs(a=>Html.CheckBox("MyCheckbox",a.isF)).Titled("");
                   columns.Add(a => a.SID).Titled("SID");
                   columns.Add(a => a.Remarks).Titled("Remarks").Encoded(false).Sanitized(false).RenderValueAs(a => Html.TextBox("textboxRemarks", a.Rem));

               }).WithPaging(10).Sortable(true).Filterable()
             </div>

All i need to do is to validate if checkbox is checked and the remarks is not empty.

This javascript code is working but my problem is even in SID 02 the remarks is showing instead of empty.

My Question is how to get the right value of each textbox row?

Any suggestion is pretty much appreciated.

1

There are 1 best solutions below

4
On

$('#btn_preview_').click(function(){
            Validate()
        });

        function Validate()
        {

            $('.mvcGrid table tr').each(function (index,item) {
                if($(this).find(' input[name=MyCheckbox]:checkbox').is(':checked')==true)
                {
                    var getText =   $.trim($(this).find(' input[name=textboxRemarks]').val());

                    alert('SID ' + $(this).find('td:eq('+index+')').text() +  ' getText ' + getText);
                }
                else
                {
                    Alert('Checkbox is unchecked');
                }
            });
        }

Try this.