0
1

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.

【JS】ボタン押下をせずファイルアップロードしたらフォーム送信する

Last updated at Posted at 2022-12-06

ファイルをアップロードした段階でフォーム送信される処理。
▼HTML

hoge.blade.php
// 送信フォーム
<form action="{{ route('user.update_profile', ['user' => $authUser]) }}" method="POST" name="imageForm" enctype="multipart/form-data">
    <input type="file" id="input_file" name="image_url" accept=".png, .jpg, .jpeg, .gif">
</form>

▼JS

hoge.blade.php
$(function () {
    $("#input_file").change(function () {
        $(this).closest("form").submit();
    });
});

ファイルがアップロードされたら、formのアクションに移行する。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?