私は私のビューに値のリストを送信するためにWeb2Pyを使用しています。Javascriptどのように選択したアイテムのIDを取得する
私のHTMLは次のようである:
<select id="DestinationOptions" onchange="SetDest(this)">
{{for key, value in dirList.iteritems():}}
<option name="DirListItem{{=key}}" id="{{=key}}"> {{=value}}</option>
{{pass}}
</select>
私のjavascriptがこのようなものです:
function SetDest(destComboBxID)
{
alert(destComboBxID.id);
var e = document.getElementById(destComboBxID);
var path = e.option[e.selectedIndex].value;
alert(path);
//document.cookie = "GD_"+file.id + "=" + file.id + ";";
}
私は最初alert()
に取得し、私はデバッグするとき、私は次のエラーを取得しますブラウワー:
Uncaught TypeError: Cannot read property 'options' of null
Q :どのように私はselcted値のIDを取得できますか?
注:あなた 'template'はこのようなものです、ない' HTML' –
は '置き換えるVAR E =のdocument.getElementById(destComboBxID);' 'VAR電子= destComboBxIDと;' –
場合それはHTMLではない、あなたはそれを何と呼ぶだろうか? * .htmlファイルからです... – fifamaniac04