Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
To Show/Hide <div> tag depending on the selection from previous drop down box

I have read many tutorials and many answers on stack overflow as well but it still does not work for me.Upon selecting an option (Yes)from drop down -> it should show the <div> tag otherwise <div> should be hidden.

Below is my code:

<h4>1. Does your school participate in the sponsored CAT4 scoring initiative?</h4>
            @{
                List<SelectListItem> listItems = new List<SelectListItem>();
                listItems.Add(new SelectListItem
                {
                    Text = "Yes",
                    Value = "True"
                });
                listItems.Add(new SelectListItem
                {
                    Text = "No",
                    Value = "False"
                });
            }
            <div class="form-group" id="PickOption">
                <div class="col-md-10">
                    @Html.DropDownListFor(model => model.ParticipateInCAT4Scoring, listItems, "<----Select Yes or No---->", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.ParticipateInCAT4Scoring, "", new { @class = "text-danger" })
                </div>

            </div>

            <div id="OnYes" class="form-group" style="display:none">
                @Html.Label("For what Grade levels?", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(m => m.GradeLevelsCAT4, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(m => m.GradeLevelsCAT4, "", new { @class = "text-danger" })
                </div>

            </div>

Below is the Script file which I am placing at bottom of View page:

@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $('#PickOption').on('change', function () {
                if ($(this).val() == 'True') {
                    document.getElementById('OnYes').style.display = "";
               

                }

                    else {
                    
                 document.getElementById('OnYes').style.display = "none";
                 
                    }
                });
            });
    </script>

}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

PickOption is the ID of the wrapping div.

Replace #PickOption on this line with the ID or selector of the select box (usually auto-generated but you can specify.

            $('#PickOption').on('change', function () {

Also since you're using jQuery, you can just do $('#OnYes').show();

https://api.jquery.com/show/

about 4 years ago · Juan Pablo Isaza Report

0

Your selector is not right, please make sure that you bind event on dropdown so add a class on dropdown

@Html.DropDownListFor(model => model.ParticipateInCAT4Scoring, listItems, "<----Select Yes or No---->", new { @class = "form-control pickerDropdown" })

Now bind the event on added class like this:

$('.pickerDropdown').on('change', function () {
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!