申し訳ありませんこれまでに質問されている場合は、例とコードスニペットを見てきましたが作業。HTMLでJavascriptを使用して選択オプションを取得し、値に基づいて文字列を表示
私はHTMLでコースを取っていますが、割り当てにはスクリプトを使用してddlをチェックし、選択したオプションに基づいてテキスト行を表示する必要があります。問題は、私がオンラインで見つけたことは、教師が提供した例とは少し違っているように見えることです(違いがあれば、Dreamweaver 2015を使用しています)。
2時間後いくつかの異なるスレッドからコードを取り除きます。
更新:警告VS HTML要素に選択した値を出力し、ここで
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> Hot Buns </title>
</head>
<script type="text/javascript">
function showDetails()
{
var x= document.getElementById("slctOrder");
var val= x.options[x.selectedIndex].text;
<!-- DW only displays item(n) and len after the dot, I typed in "text" manually -->
document.forms["frmOrder"]["Details"].value = val;
<!-- I'm just trying to have it display anything at this point,
same as above, I typed "value" since DW doesn't seem to recognize this code
(this is from the teacher's example) -->
}
</script>
<body>
<p> <h2> Welcome to Hot Buns </h2> <br> <h3> Ham can we bee'f service? </h3></p>
<p> <h2> Place an order </h2> </p>
<form method="get" name="frmOder">
<select name="slctOrder" onChange="showDetails();">
<!-- I'm trying to call the function showDetails()
but neither onChange here nor onClick in the option tag seem to accomplish that -->
<option hidden selected="selected" value="0"> please select one of today's specials </option>
<option value="1" onClick="showDetails();"> Last of the Mo-jicama </option>
<option value="2" onClick="showDetails();"> Cheesus Is Born Burger </option>
<option value="3" onClick="showDetails();"> Beets of Burden Burger </option>
<option value="4" onClick="showDetails();"> Paranormal Pepper Jack-tivity Burger </option>
</select>
<output name="Details"/>
</form>
</body>
</html>
何が問題なのですか?何が効いていないのですか? – dstarh