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.

2
  • please post some sample code. Commented Apr 11, 2014 at 8:37
  • There is no value associated with checkbox, thus $("#right").val() is returning nothing Commented Apr 11, 2014 at 8:38

3 Answers 3

8

Use:

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

OR

$("#right").is(":checked")
Sign up to request clarification or add additional context in comments.

Comments

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"));

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.