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?

More than 1 year has passed since last update.

HTML【個人用ドキュメント】

Last updated at Posted at 2022-04-04

form

onsubmit属性

「onsubmit」は「formタグ」内の属性として記述するようになっており、submitされた時に起動するイベントです。

preventDefault()メソッド

preventDefault() メソッドは、ユーザーエージェントに、イベントが明示的に処理されない場合にその既定のアクションを通常どおりに行うべきではないことを伝えます。通常submitするとその情報を送信してページを更新することですが、それを防ぐことができます。

formの記述例

//onsubmit属性,event.preventDefault()
<form id="bank-form" class="form" onsubmit="initializeUserAccount(); event.preventDefault()">
    <div class="form-group">
        <input type="email" name="userEmail" class="form-control" placeholder="Email" required>
    </div>
    <div class="form-group">
        <input type="text" name="userFirstName" class="form-control" placeholder="First name" required>
    </div>
    <div class="form-group">
        <input type="text" name="userLastName" class="form-control" placeholder="Last name" required>
    </div>
    <div class="form-group">
        <input type="number" class="form-control" name="userFirstDeposit" aria-describedby="emailHelp" placeholder="Enter your first deposit" required>
    </div>
    <div class="form-group">
        <div class="form-check">
            <input class="form-check-input" type="radio" name="userAccountType" id="userAccountType1" value="savings" checked required>
            <label class="form-check-label" for="userAccountType1">
                Savings
            </label>
        </div>
        <div class="form-check">
            <input class="form-check-input" type="radio" name="userAccountType" id="userAccountType2" value="checkings" required>
            <label class="form-check-label" for="userAccountType2">
                Checkings
            </label>
         </div>
    </div>
    <button type="submit" class="btn btn-primary col-12">Submit</button>
</form>

input

required属性

input要素のrequired属性は、その入力項目が必須属性であることをブラウザに知らせることができる。HTML5では、required属性を設定するだけでJavaScriptによる入力チェックがなくてもエラーメッセージを表示させることが可能。

aria-describedby属性

button

0
0
0

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?