Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda