How can I check if a checkbox is checked in view page with razor and if checked display a textbox!
I'm new in asp.net mvc and razor, still learning.
View Code
@Html.CheckBoxFor(m => m.SupportRequired)
@Html.TextBoxFor(m => m.AssistName new { @class = "form-control" })
You can use JavaScript like this:
@Html.CheckBoxFor(m => m.SupportRequired , new { id = "MyChk", onchange = "valueChanged()"})
@Html.TextBoxFor(m => m.AssistName , new { id = "MyTxt" , @class = "form-control" })
<script type="text/javascript">
function valueChanged() {
if ($('#Mychk').is(":checked"))
$("#MyTxt").show();
else
$("#MyTxt").hide();
}
</script>
Edit
For show or hide in page load you need add this code:
$(document).ready(function() {
valueChanged();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With