开发者

Switch Case not working

开发者 https://www.devze.com 2023-03-09 16:16 出处:网络
$(\"select[name=program]\").change(function () { switch ($(\"select[name=program]\").val()) { case \'Women\\\'s\':
        $("select[name=program]").change(function () {
            switch ($("select[name=program]").val()) {
                case 'Women\'s':
                    $("tr#levelCheck").html(
                        "<th>Level</th>" +
                        "<td>" + 
                            "<select name='level'>" +
                                "<option value='Senior'>Senior</option>" +
                                "<option value='Junior'>Junior</option>" +
                            "</select>" +
                        "</td>"
                    );
                default:
                $("tr#levelCheck").html("");
            }
        });

Here is my html

<tr>
    <th>Program</th>
    <td>{html_options name="program" output="$program" values="$program"}</td>
</tr>
<tr id="levelCheck"></tr>

I just w开发者_StackOverflow社区ant my other menu to show up when I select one of my other menu options from the program dropdown. Basically, I select Women's, another menu shows up below and I am off to the races. Why isn't my dropdown displaying when I select my Women's Option?


You need a break before your default case. Right now, you build the menu and then you fall into the default case and your HTML is cleared.

$("select[name=program]").change(function () {
            switch ($("select[name=program]").val()) {
                case 'Women\'s':
                    $("tr#levelCheck").html(
                        "<th>Level</th>" +
                        "<td>" + 
                            "<select name='level'>" +
                                "<option value='Senior'>Senior</option>" +
                                "<option value='Junior'>Junior</option>" +
                            "</select>" +
                        "</td>"
                    );
                    break;
                default:
                    $("tr#levelCheck").html("");
                    break;
            }
        });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号