2

In my application, user has a choice to check or uncheck a field "Right". I could able to set the model values to the checkbox using @html.checkboxfor

 @Html.CheckBoxFor(x => x.Right, new { id="right"})

Can someone help me how to get the value using the id. For now i am using $("#right").val() to get the value. But it is not working. Someone please help me to solve this issue.

user3363329
  • 79
  • 1
  • 2
  • 8

3 Answers3

8

Use:

 $("#right").prop('checked') 

OR

$("#right").is(":checked")
Alexandru Chichinete
  • 1,166
  • 12
  • 23
2

This is working for me to get @Html.CheckBoxFor status using JS .. Thanks kikyalex

@Html.CheckBoxFor(model => model.IA.InProcess, new { @id = "cbinPro" })

alert($("#cbinPro").is(":checked"));
RAVI VAGHELA
  • 877
  • 1
  • 10
  • 12
1

You can get the checked checkbox values like this

$('input:checkbox[name=right]').each(function() {
if($(this).is(':checked'))
  alert($(this).val());});

Please check this Link. It can be helpful

Nag
  • 689
  • 1
  • 5
  • 15