Jaima Joseph

Jaima Joseph

  • NA
  • 94
  • 107.5k

How to check checkboxes on view load in mvc?

Jun 17 2014 3:58 AM

Hi,

Please help....

I have a list of records in my view and each records there is a corresponding check box too. On page load I want to check the checkbox for each row ,if it is having an entry in some other table.How to do it? I have tried the following javascript which I called the on load event of check box.i.e,
 

@foreach (var item in Model)

{

<tds for some other fields></td> 

<td>

<input type="checkbox" id="chk" name="chk" title="@item.QuoteId" value="@item.QuoteId" class="testchk checkbox" onload="checkCheckbox();"/>

</td>

 
 
and the javascript is:
 

<script type="text/javascript" language="javascript">

function checkCheckbox() {

alert();

var idquot = $("#selquot").val();

alert(idquot);

$.ajax({

url: '@Url.Action("selectCheckbox", "Quote")',

data: {

quotid: idquot

},

success: function (data) {

alert();

if (data == true)

{

$(".testchk").is(':checked');

}

//$('#minQotId').html(data);

}

});

};

</script>

it is not caaling the javascript function even....
 
any help will be appreciated... 

Answers (2)