回答編集履歴
1
複数対応
test
CHANGED
@@ -19,3 +19,31 @@
|
|
19
19
|
例が一つしかないためちょっとわからなかったのですが、複数行あるのでしょうか?
|
20
20
|
|
21
21
|
その場合はformで監視したほうがいいかもしれません(idは変える必要があります)。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
-- 15:17追記 複数対応
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
```HTML
|
30
|
+
|
31
|
+
<option value="test_name" data-disp="test_d_name" data-address="test_address">test_name</option>
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```JavaScript
|
38
|
+
|
39
|
+
document.getElementById('select_test_info').addEventListener('change', function(event) {
|
40
|
+
|
41
|
+
var option = this.options[this.selectedIndex];
|
42
|
+
|
43
|
+
document.querySelector('[name="test_d_name"]').value = option.getAttribute('data-disp');
|
44
|
+
|
45
|
+
document.querySelector('[name="test_address"]').value = option.getAttribute('data-address');
|
46
|
+
|
47
|
+
}, false);
|
48
|
+
|
49
|
+
```
|