KyLim KyLim - 4 months ago 15
Javascript Question

jquery fail hide and show div

I trying to hide and show a base on dropdownlist selection but fail,no idea where i did wrong,please help..

$(document).ready(function () {
$('#code').on('change', function () {
if (this.value == 'T4')
{
$("#TR").show();
}
else {
$("#TR").hide();
}
});
});

<div class="form-group" style='display:none;' id='TR'>
<label for="Training Fees(RM)" style="color:black">Training Fees(RM)</label>
<div class="col-sm-3">
<asp:TextBox runat="server"ID="RM_TEXT" placeholder="RINGGIT" />
</div>
</div>


my dropdownlist :

<div>
<asp:DropDownList ID="Code" runat="server"></asp:DropDownList>
</div>


my dropdownlist DataTextField and DataValueField:
DROPDOWNLIST

Answer

Kindly Check DropDown list ID in inspect element,try to put something ct100_

OR use

<asp:DropDownList ID="Code" runat="server" onchange="javascript:return dropdown(this);"></asp:DropDownList>

Javascirpt

 function dropdown(val)
    {
      if ($(val).val() == 'T4') {
        $("#TR").show();
      }
      else {
                 $("#TR").hide();
      }
    }