How To Hide And Show Div In Asp.net Mvc 5 Using Dropdownlist Change Event
I am trying to hide and show div in my mvc 5 project using dropdownlist change event, i have researched, and luckily i found this code online, but it doesn't seem to work for me, i
Solution 1:
I found the problem. That is the value of $("#CountryID") is CountryID instead of CountryName.
$(function () {
$(document).ready(function() {
$("#CountryID").change(function () {
if ($(this).val() != "Ghana") { // It doesn't work over here.
$("#showStateLga").show();
} else {
$("#showStateLga").hide();
}
});
});
});
There are 2 ways to fix it. First
if ($(this).val() != "2") { // Replace the match text to CountryID.
Or
if ($(this).find(':selected').text() != "Ghana") { // Replace .val() to .find(':selected').text().
Post a Comment for "How To Hide And Show Div In Asp.net Mvc 5 Using Dropdownlist Change Event"