セレクトボックスの選択肢を選んでからボタンをクリックすると
選択肢のvalueがアラートに出る
コード.gs
function doGet() { return HtmlService.createHtmlOutputFromFile("index"); } |
意訳この機能がやること 指定したHTMLファイルを表示する |
index.html
<!DOCTYPE html> <html> <body> <select id="select1"> <option value="選択肢1">選択肢1</option> <option value="選択肢2" selected>選択肢2</option> <option value="選択肢3">選択肢3</option> </select> <br><br> <button type="button" id="bt">ボタン</button> <script> document.getElementById("bt").onclick = get_select1; function get_select1() { var select1 = document.getElementById("select1"); var index = select1.selectedIndex; var value = select1[index].value; alert(value); } </script> </body> </html> |
意訳これはHTML5文書です セレクトボックスを置く 1つめの選択肢 2つめの選択肢 3つめの選択肢 ボタンを置く ボタンがクリックされたらget_select1を実行する この機能がやること 対象のセレクトボックスを取得して 何番目の選択肢が選択されているかを取得して そのvalueを取得して アラートに出す |
もっと簡単に
document.getElementById("select1").value
でも取得できる。