0

I am begginer in JavaScript, and I am currently working one application for date and time validation. I have one radio button which control content from dropdown, will show or not depending is radio button selected to Yes or No. One stupid think which I can not understand, when I select radio button to No, and after refreshing page, or even when date and time validation appear, the content of dropdown meanu is again display. So picture will demostrante situation better

enter image description here

And also my code

   $(document).ready(function () {
        $("input[name$='Chapel']").click(function () {
            var test = $(this).val();
            if (test == 'No') {
                $("div#hideChapel").hide();
            }
            else {
                $("div#hideChapel").show();
            }
        });
    });

HTML

<div class="form-group">
    <label class="control-label col-md-3" for="Chapel">Chapel</label>
    <div class="col-md-9">
        <label class="radio-inline">
            <div class="choice" id="uniform-Chapel"><span class=""><input class="styled" htmlattributes="{ checked = true }" id="Chapel" name="Chapel" type="radio" value="Yes" autocomplete="off"></span></div>
            Yes
        </label>
        <label class="radio-inline">
            <div class="choice" id="uniform-Chapel"><span class="checked"><input checked="checked" class="styled" htmlattributes="{ checked = true }" id="Chapel" name="Chapel" type="radio" value="No" autocomplete="off"></span></div>
            No
        </label>
        <span class="field-validation-valid text-danger" data-valmsg-for="Chapel" data-valmsg-replace="true"></span>
    </div>
</div>

P.S Function work fine, but only if I get some require message in form after I submit form, I get this stupid bug. Any comment or suggestion how to avoid this or even solve it. Thank you :)

rick
  • 1,742
  • 13
  • 21
  • You currently only change the visibility on click, you should also check which of the buttons is selected on page load. – FINDarkside Jun 12 '18 at 11:55
  • post the html too. thanks – rick Jun 12 '18 at 11:55
  • 2
    When you refresh the page it gets its original state, no matter what you've clicked before. You need some sort of persistance if you want to save what you did – baao Jun 12 '18 at 11:55
  • @rick I post HTML code –  Jun 12 '18 at 12:08
  • @baao After submit form, if I get some validation message, the content is dissapeage again. So not even if I refresh page but also If I get validation message –  Jun 12 '18 at 12:10

0 Answers0