0

I'm trying to show MeetingDiv when IsAnonymous is checked and when IsMeeting is checked, MeetingTextBox should be shown.

Tried .click, .change and live and nothing worked. I don't know where I'm wrong.

<div class="col-md-4 sidePad" >
 @Html.Label("Is Anonymous")
 @Html.CheckBoxFor(p => p.IsAnonymous, new { id = "CBAnonymous"})
</div>

<div class="col-md-6" id="MeetingDiv" style="display:none">
 @Html.Label("Is Meeting")
 @Html.CheckBoxFor(p => p.IsMeeting, new { id = "CBMeeting"})
</div>

<div class="col-md-6" id="MeetingTextBox" style="display:none">
 @Html.Label("Meeting Name")
 @Html.TextBoxFor(p => p.MeetingName, new { id = "TBMeetingName"})
</div>

<script>
    $(function () {
        $("#CBAnonymous").click(function () {
            if ($(this).prop("checked")) {
                $("#MeetingDiv").show();
            } else {
                $("#MeetingDiv").hide();
            }
        });
    });
</script>
RubioRic
  • 2,442
  • 4
  • 28
  • 35
  • Have you tried `$(this).is(":checked")` or `$(this).attr("checked") === true`? Try debugging with `console.log($(this).prop("checked"))`, see what it returns. – Tetsuya Yamamoto May 14 '18 at 06:59
  • checked. Not working, even i put debugger at if control is not coming to condition when i'm checking checkbox, and when i put it before `#CBAnonymous` click it's executing even without checking the checkbox @TetsuyaYamamoto – akshay sahu May 14 '18 at 09:10
  • Did you getting JS errors in console? I tried your example and seems to be working fine, see [this fiddle](https://dotnetfiddle.net/kDBWZh). If you get error(s), put it inside the question. – Tetsuya Yamamoto May 14 '18 at 09:44
  • Not getting in console but in runtime. In my project i have already included `jquery-1.10.2.min.js` and again i'm using `jquery/1.11.0/jquery.min.js` this could be the possible reason @TetsuyaYamamoto – akshay sahu May 15 '18 at 03:06
  • Using 2 different versions of jQuery in same page may cause runtime conflicts. If you really want to use different jQuery versions, read this post: [Can I use multiple versions of jQuery on the same page?](https://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page) – Tetsuya Yamamoto May 15 '18 at 03:11
  • @akshaysahu: Please double check where: `$(this)` is pointing to, and make sure it's pointing to: `$("#CBAnonymous")` – k.vincent May 15 '18 at 10:27

1 Answers1

0

Try this

$('#CBAnonymous').change(function(){
    if(this.checked)
         $("#MeetingDiv").show();
    else
        $("#MeetingDiv").hide();