按下时选择下拉列表时显示消息

时间:2013-06-11 08:55:31

标签: php drop-down-menu menu

我有一个用PHP,jQuery和Boostrap编写的问卷。用户必须通过复选框或下拉菜单选择一些答案。当他们按下下一个按钮(箭头)时,系统必须检查他们是否选择了一个选项。如果没有,则会出现一条简单的消息。

    <label for="vraag1">Ik ben een...</label>
    <select name="vraag1" class="">
    <option value="">-- kies een antwoord --</option>
    <option value="antw1"<?php echo $_POST['vraag1'] == "antw1" ? " selected" : ""; ?>>Jongen</option>
    <option value="antw2"<?php echo $_POST['vraag1'] == "antw2" ? " selected" : ""; ?>>Meisje</option>
    </select>

按钮

<div class="pageNext span1"><a href="#stap3" data-toggle="tab" class="tabber"><img id="next_stap3" src="<?php echo BASEURL; ?>img/arrow-right.png" alt="Volgende pagina" title="Volgende pagina" /></a></div>

谢谢:)

1 个答案:

答案 0 :(得分:1)

$( function(){                                                          // Dom ready
    $( "#id-of-your-button" ).click( function(){                        // Trigger click in button
        if( ( $( "input[type=checkbox]:checked" ).length === 0 ) ||     // We have a checkox checked
            ( $( "select" ).val() === "" ) )                            // We have selected an option in the select?
        {
            $( "body" ).prepend( "Dude you must select something!" )    // Insert message
            return false;                                               // Prevent default behavior and bubbling in the button
        }
    } );
} );