LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Sunday, December 31, 2017

セレクトボックスのオプションを選択状態にする

JavaScriptでセレクトボックスのオプションを選択状態にする




セレクトボックスを作る では
<option value="選択肢2" selected>選択肢2</option>
のようにオプションに直接selectedを入れました

今回はJavaScriptで指定したindexをselectedにしています
document.getElementById("select1").selectedIndex = 1;




コード.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">選択肢2</option>
      <option value="選択肢3">選択肢3</option>
    </select>
  <script>
    document.getElementById("select1").selectedIndex = 1;
  </script>
</body>
</html>
意訳
これはHTML5文書です


セレクトボックスを置く
1つ目の選択肢
2つ目の選択肢
3つ目の選択肢


1番目の選択肢を選択する(選択肢1は0番目)





Latest post

Extracting data from Google Sheets with regular expressions

Introduction Regular expressions are a powerful tool that can be used to extract data from text.  In Google Sheets, regular expressions ca...