Reputation: 45
I have below table -
<tbody>
@for (int i = 0; i < Model.Count; i++)
{
<tr>
<td>
@Html.CheckBoxFor(modelItem => modelItem[i].ShouldImport, new { @class = "sid", @onclick = "DisplayDetailedInfo(this)" })
</td>
<td>
@Html.DisplayFor(modelItem => modelItem[i].Name)
@Html.HiddenFor(modelItem => modelItem[i].Name)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem[i].AccountNumber)
@Html.HiddenFor(modelItem => modelItem[i].AccountNumber)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem[i].AccountType)
@Html.HiddenFor(modelItem => modelItem[i].AccountType)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem[i].AccountStatus)
@Html.HiddenFor(modelItem => modelItem[i].AccountStatus)
</td>
<td>
@Html.CheckBoxFor(modelItem => modelItem[i].IsLatePayment)
</td>
</tr>
}
My Javascript Function is follows -
function DisplayDetailedInfo(data) {
console.log(data);
var vval = $(data).val();
var anotherval = $(this).is(':checked')
console.log(anotherval);
if (anotherval)
{
console.log("Hi");
}
}
I need assistance why I am getting value as false although I am checking the Checkbox. I am new to razor and Jquery and need assistance.
Upvotes: 0
Views: 961
Reputation: 696
The keyword this
in your case is returning window
so you have to replace it with data
as follows:
function DisplayDetailedInfo(data) {
console.log(data);
var vval = $(data).val();
var anotherval = $(data).is(':checked');
console.log(anotherval);
if (anotherval)
{
console.log("Hi");
}
}
Upvotes: 1