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.

javascriptを用い、option valueの数値を表示かつ、2の倍数かどうかの判定がしたいです。

Posted at

javascripを用いて、例えばりんごを選択すれば2と返し、
さらに、2の倍数であるかを判定するプログラムを作りたいです。
ちなみに自分の知識量では、2の倍数の場合、
if( ( Number % 2 ) != 0 ) {
}として、
違うもの(ここでは1,3,5)をelseと返すことしかわかりかねます。
以下はhtmlです。

<html lang="ja">
<head>
  <meta charset="utf-8">
  <title>サンプル</title>
  <script src="sample.js"></script>
</head>
<body>
  <select id="sel1">
    <option value="01">みかん</option>
    <option value="02">りんご</option>
    <option value="03">バナナ</option>
    <option value="04">ぶどう</option>
    <option value="05">レモン</option>
  </select>
  <input type="button" value="ボタン" onclick="getValue('sel1');">
</body>
</html>

以下はjsです。

<script type="text/javascript">

function ShowValue(){
  let SELECT_VALUE = document.GetElementById('sel1').value;
let TEXT_VALUE ='';
if(SELECT_VALUE = 3){
  TEXT_VALUE = '●';
}else{
  TEXT_VALUE = '✕';
};
  document.GetElementById('sv').innerHTML = '<p><b>' & SELECT_VALUE & '</b></p><p>' & TEXT_VALUE & '</p>';
};
</script>
<script type="text/javascript">

function ShowValue(){
  let SELECT_VALUE = document.GetElementById('sel1').value;
  document.GetElementById('sv').innerHTML = '<b>' & SELECT_VALUE & '</b>';
};
</script>
0
1
1

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?