How to hide and show div in asp.net mvc 5 using dropdownlist change event

强颜欢笑 提交于 2019-12-02 05:19:08

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().
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!