0
2

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 5 years have passed since last update.

【初心者向け】覚えて損はないJSによるform系要素の操作をcodepenで説明

Last updated at Posted at 2019-10-30

普段はほとんどJQueryで書いています。
とても基本的なことですが、大切なことだと思うのでまとめています。
どれもトリガーはclickになっています。

テキストボックス/テキストエリアの値を取得

valueプロパティでテキストエリアの中身を取得できます。

See the Pen joWNQp by n-kaminaga (@n-kaminaga) on CodePen.

セレクトボックスの値を取得

セレクトボックスもvalueで取得できます。

See the Pen joWNQp by n-kaminaga (@n-kaminaga) on CodePen.

ラジオボタンの値を取得

checkedプロパティで取得ができます。
for文で同じneme属性のラジオボタン全てのチェックの有無を確認します。

See the Pen mYPPaE by n-kaminaga (@n-kaminaga) on CodePen.

チェックボックスの値を取得

checkedプロパティで取得ができます。
チェックボックスは複数選択可能なので、for文で同じneme属性のチェックボックス全てのチェックの有無を確認し、配列にpushしていきます。

See the Pen xNVORb by n-kaminaga (@n-kaminaga) on CodePen.

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?