LoginSignup
0
1

More than 3 years have passed since last update.

チェックボックスでチェックされている値を全て取得するワンライナー

Last updated at Posted at 2020-01-28
const values = [...document.getElementsByName('checkBoxName')].filter(elm => elm.checked).map(elm => elm.value);
if (values.length === 0) {
  alert('チェックボックスをチェックしてください。')
}

ES2015じゃないと動かないですが、新しいブラウザなら動くと思います。

domの配列だと機能が足りないので、一旦、jsの配列に変換しているところがポイントかと思います。

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