0

I have a checkbox field in a .cshtml form with next attributes:

@Html.CheckBox("InFooter", new { @class = "form-control", @id = "edit_rssFeed_InFooter" })

Now, using ajax I am setting value to "value" attribute of this checkbox:

$('#edit_rssFeed_InFooter').val(rss.InFooter);

where InFooter is boolean value (true or false). So, with this line, I get value=true/false attribute generated.

I would like to set attribute checked="checked" when attribute value=true. How can I do that?

2 Answers 2

1

You use as

  $('#edit_rssFeed_InFooter').prop("checked",rss.InFooter);
Sign up to request clarification or add additional context in comments.

1 Comment

Wow! I listed the same answer 1 second before you... Never been that close before :)
1

Always use prop('checked', value) when dealing with check boxes (not val()).

See if this does the trick:

$('#edit_rssFeed_InFooter').prop('checked', rss.InFooter);

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.