选择下拉列表字段选项时显示文本框

Show textbox when dropdownlist field option is selected

在选择选项 Jiná společnost: 的下拉列表字段中,我需要显示 JinaSpolecnostTextBox 文本框

你能帮帮我吗?

$('[PrimaGroupList]').change(function() {
  var SelectedValue = $('[PrimaGroupList]').val();
  if (SelectedValue == "Jiná společnost:")
    $("#JinaSpolecnost").show();
  else
    $("#JinaSpolecnost").hide();
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div>
  <div class="row" id="Bod1">
    <div class="col-xs-12 col-md-6">
      <label for="DropDownList1">Vyberte z možnost&#237;</label> *
      <select class="custom-select form-control" data-val="true" data-val-required="Vyplňte toto pole." name="[PrimaGroupList]" tabindex="1">
        <option value="FTV Prima, spol. s r. o.">FTV Prima, spol. s r. o.</option>
        <option value="MEDIA CLUB, s.r.o.">MEDIA CLUB, s.r.o.</option>
        <option value="PRIMA GROUP MANAŽERSKÁ, a.s.">PRIMA GROUP MANAŽERSK&#193;, a.s.</option>
        <option value="PRIMA DOMA MEDIA, s.r.o.">PRIMA DOMA MEDIA, s.r.o.</option>
        <option value="CAR PR MEDIA, s.r.o.">CAR PR MEDIA, s.r.o.</option>
        <option value="Prima produkce, s.r.o.">Prima produkce, s.r.o.</option>
        <option value="PLAYzone s.r.o.">PLAYzone s.r.o.</option>
        <option value="PLAYPRESS s.r.o.">PLAYPRESS s.r.o.</option>
        <option value="RADIO UNITED BROADCASTING s.r.o.">RADIO UNITED BROADCASTING s.r.o.</option>
        <option value="Jiná společnost:">Jin&#225; společnost (uveďte)</option>
        <option selected="selected" value=""></option>
      </select>
    </div>
    <div class="col-xs-12 col-md-6" id="JinaSpolecnost" style="display:none">
      <label for="[JinaSpolecnostTextBox]" class=>N&#225;zev jin&#233; společnosti</label> *
      <input class="form-control" data-showSuggestionsOnClick="true" data-val="true" data-val-required="Vyplňte toto pole." name="[JinaSpolecnostTextBox]" placeholder="" tabindex="1" type="text" value="" /><input name="[JinaSpolecnostTextBox].IsHtml"
        type="hidden" value="True" /><input name="[JinaSpolecnostTextBox].defaultFormatHtml" type="hidden" value="True" /><span class="field-validation-valid" data-valmsg-for="[JinaSpolecnostTextBox]" data-valmsg-replace="true"></span>
    </div>
  </div>
</div>

您的代码中的问题是因为 $('[PrimaGroupList]') 不是有效的选择器。您需要使用 'attribute selector' 通过其 name 检索元素。代码应如下所示:

let $textbox = $("#JinaSpolecnost");

$('select[name="[PrimaGroupList]"]').change(function() {
  var selectedValue = $(this).val();
  if (selectedValue == "Jiná společnost:")
    $textbox.show();
  else
    $textbox.hide();
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div>
  <div class="row" id="Bod1">
    <div class="col-xs-12 col-md-6">
      <label for="DropDownList1">Vyberte z možnost&#237;</label> *
      <select class="custom-select form-control" data-val="true" data-val-required="Vyplňte toto pole." name="[PrimaGroupList]" tabindex="1">
        <option value="FTV Prima, spol. s r. o.">FTV Prima, spol. s r. o.</option>
        <option value="MEDIA CLUB, s.r.o.">MEDIA CLUB, s.r.o.</option>
        <option value="PRIMA GROUP MANAŽERSKÁ, a.s.">PRIMA GROUP MANAŽERSK&#193;, a.s.</option>
        <option value="PRIMA DOMA MEDIA, s.r.o.">PRIMA DOMA MEDIA, s.r.o.</option>
        <option value="CAR PR MEDIA, s.r.o.">CAR PR MEDIA, s.r.o.</option>
        <option value="Prima produkce, s.r.o.">Prima produkce, s.r.o.</option>
        <option value="PLAYzone s.r.o.">PLAYzone s.r.o.</option>
        <option value="PLAYPRESS s.r.o.">PLAYPRESS s.r.o.</option>
        <option value="RADIO UNITED BROADCASTING s.r.o.">RADIO UNITED BROADCASTING s.r.o.</option>
        <option value="Jiná společnost:">Jin&#225; společnost (uveďte)</option>
        <option selected="selected" value=""></option>
      </select>
    </div>
    <div class="col-xs-12 col-md-6" id="JinaSpolecnost" style="display:none">
      <label for="[JinaSpolecnostTextBox]" class=>N&#225;zev jin&#233; společnosti</label> *
      <input class="form-control" data-showSuggestionsOnClick="true" data-val="true" data-val-required="Vyplňte toto pole." name="[JinaSpolecnostTextBox]" placeholder="" tabindex="1" type="text" value="" /><input name="[JinaSpolecnostTextBox].IsHtml"
        type="hidden" value="True" /><input name="[JinaSpolecnostTextBox].defaultFormatHtml" type="hidden" value="True" /><span class="field-validation-valid" data-valmsg-for="[JinaSpolecnostTextBox]" data-valmsg-replace="true"></span>
    </div>
  </div>
</div>