3

何も選択しておらず、機能しなかった場合は、警告する必要があります。何が問題なのかを表示し、ウィンドウで警告する必要があります。

<!DOCTYPE html>
<html>
<head>
<select id="ddlView">
<option value="0">Select</option>
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3">test3</option>
</select>  
<input type="button" onclick="myFunction()" value="select" />

<script>
function Validate()
{
var e = document.getElementById("ddlView");
var strUser = e.options[e.selectedIndex].value;

var strUser1 = e.options[e.selectedIndex].text;
if(strUser==0)
{
alert("Please select a user");
}
}
</td></head>

</html>
4

4 に答える 4

6

ここには複数の問題があると思います。

  1. body タグを追加する必要があります
  2. ボタンに正しい関数名を設定します。
  3. スクリプトの終了タグが必要です

これを試してください:

<!DOCTYPE html>
<html>
    <body>
        <select id="ddlView">
            <option value="0">Select</option>
            <option value="1">test1</option>
            <option value="2">test2</option>
            <option value="3">test3</option>
        </select>  
        <input type="button" onclick="Validate()" value="select" />

        <script type="text/javascript">
            function Validate()
            {
                var e = document.getElementById("ddlView");
                var strUser = e.options[e.selectedIndex].value;

                var strUser1 = e.options[e.selectedIndex].text;
                if(strUser==0)
                {
                    alert("Please select a user");
                }
            }
        </script>
    </body>
</html>
于 2013-03-12T17:38:27.163 に答える
0

これはフォーム処理スクリプトに含まれている必要があります。コードの先頭に追加するだけで、送信されたかどうかを確認できます。

// Place this atop of your script.
if(isset($_POST)) {
    if($_POST['member_id']) {
        // Your codes here
    }
}
于 2019-04-05T12:14:39.500 に答える