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

javascriptでselectの値を取得する方法

Posted at

javascriptでselectで選ばれた値を取得する方法

<select name="num" id="select-num"> <!-- selectにidを設置 -->
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
</select>  
const Num = document.getElementById('select-num') 

Num.onchange = function(){         /* onchangeでselectが変更されるたびに値を取得しています */

  alert(this.value);
}
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?