I'm trying to change an TextBoxFor readonly property on whether a checkbox is checked or not. I have read other posts but the answers don't seem to work for me.. I any one please would point out what i miss in the code below.
<div class="editor-label">
@Html.LabelFor(m => m.AddFitbit)
</div>
<div class="editor-field" id="checkBox">
@Html.CheckBoxFor(m => m.AddFitbit)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Mail)
</div>
<div class="editor-field" id="userMail">
@Html.TextBoxFor(m => m.Mail)
</div>
<br />
<input class="submit" type="submit" value="@LangResources.Create" />
<button onclick="history.back(); return false;">@LangResources.BtnCancel</button>
</div>
</article>
}
@Html.ValidationSummary(true, LangResources.ScreenAddGeneralError)
<script type="text/javascript">
$(function() {
$('#checkBox').change(function () {
if ($(this).is(':checked')) {
$('#userMail').attr('readonly');
} else {
$('#userMail').removeAttr('readonly');
}
});
});
</script>