質問で述べているように、ドロップダウンメニューから要素を取得し、それを格納されている変数に関連付けてから、ifステートメントを使用して変数をWebページの別の場所に配置しようとしています。以下の例には月のドロップダウンがあり、「getElementByID」を使用して日数を投稿したいと思います。これを機能させるための良い方法は何ですか?ARRGH私はまったくの初心者です...どんな助けもいただければ幸いです。これが私のhtml/javascriptですがCSSを良くも悪くも除外しています-
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<script language="javascript">
function displayDaysInTheMonth()
{
var thirty = document.monthForm.30
var thirtyone = document.monthForm.31
var twentyeight = document.monthForm.28
if (thirty == 'true' )
{
document.monthForm.getElementById('a').innerHTML = "has 30 days";
return;
}
else if (thirtyone == 'true' )
{
document.monthForm.getElementById('b').innerHTML = "has 31 days";
return;
}
else if (twentyeight == 'true' )
{
document.monthForm.getElementById('c').innerHTML = "has 28 days";
return;
}
}
</script>
</head>
<body>
<div class='container'>
<h2> David Platt's</h2>
<h2>Monthly Day Count</h2>
<form name='monthForm'>
<select name='months' onchange='displayDaysInTheMonth();' style='float: left; margin: 0 10px 10px 15px;'>
<option name = '31'>January</option>
<option name = '28'>February</option>
<option name = '31'>March</option>
<option name = '30'>April</option>
<option name = '31'>May</option>
<option name = '30'>June</option>
<option name = '31'>July</option>
<option name = '31'>August</option>
<option name = '30'>September</option>
<option name = '31'>October</option>
<option name = '30' >November</option>
<option name = '31'>December </option>
</select>
<div name='result' class='result' id = 'a' id = 'b' id = 'c' >has # days.</div>
<div class='clear'></div>
</form>
</div>
</body>
</html>