0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【フォームで送信したら中身を空白に戻す方法】

Last updated at Posted at 2025-07-07

javascriptファイル内にてresetメソッドを使用してフォームの内容をリセットすることができる!

定型文

function リセットする関数の名前 {
  document.フォームの名前.reset();
}

例文

        <h2>【フォーム送信イベント】</h2>
        <form onsubmit="handleSubmit(event)" name = "formResetEvent">
        <input type="text" placeholder="名前を⼊⼒してください">
        <button type="submit">送信</button>
        </form>
        <p id="submitMessage"></p>
        <script>
            function handleSubmit(event) {
                event.preventDefault(); // フォーム送信をキャンセル
                document.getElementById('submitMessage').innerHTML = 'フォームが送信されました!';
                document.formResetEvent.reset();//ここでフォームの中身をリセットしてる。
            }
        </script>
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?