teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

複数対応

2018/01/11 06:18

投稿

x_x
x_x

スコア13749

answer CHANGED
@@ -8,4 +8,18 @@
8
8
  }, false);
9
9
  ```
10
10
  例が一つしかないためちょっとわからなかったのですが、複数行あるのでしょうか?
11
- その場合はformで監視したほうがいいかもしれません(idは変える必要があります)。
11
+ その場合はformで監視したほうがいいかもしれません(idは変える必要があります)。
12
+
13
+ -- 15:17追記 複数対応
14
+
15
+ ```HTML
16
+ <option value="test_name" data-disp="test_d_name" data-address="test_address">test_name</option>
17
+ ```
18
+
19
+ ```JavaScript
20
+ document.getElementById('select_test_info').addEventListener('change', function(event) {
21
+ var option = this.options[this.selectedIndex];
22
+ document.querySelector('[name="test_d_name"]').value = option.getAttribute('data-disp');
23
+ document.querySelector('[name="test_address"]').value = option.getAttribute('data-address');
24
+ }, false);
25
+ ```