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.

フォームsubmitした時に確認アラートの通知をする方法

Posted at

概要

LaravelのテンプレートエンジンBladeを使っている時に確認アラートを出す。
フォームの内容は何かしらの期限を変更するもので、入力した期限が現在の期限を越える場合に更新していいかの確認アラートを出したいとする。

<form action="{{ route('ルーティング') }}" method="post" onsubmit="return mail_alert('{{ 現在の期限 }}');" novalidate>
  @method('PUT')
  @csrf
  <fieldset class="form-group">
  <div class="row">
    <legend>期限</legend>
    <div class="form-check form-check-inline">
        <input type="text" name="name" value="value" class="form-control" id="id">
    </div>
  </div>
  </fieldset>
</form>

@push('script')
@include('_scripts.parsley')
<script>
  function mail_alert(現在の期限) {
    let 入力期限 = document.getElementById('id').value;
    if (現在の期限 < 入力期限) {
      return confirm('更新してよろしいですか?')
    }
  }
</script>
@endpush
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?