回答編集履歴
1
帰宅後確認
answer
CHANGED
@@ -3,4 +3,34 @@
|
|
3
3
|
sample.value.length == 0 や
|
4
4
|
sample.value.value == ""
|
5
5
|
|
6
|
-
なら恐らく大丈夫だと思います。
|
6
|
+
なら恐らく大丈夫だと思います。
|
7
|
+
|
8
|
+
帰宅して確かめてみました。下記コードで問題なく動作したので
|
9
|
+
!sample.valueでもOKでした。
|
10
|
+
なので問題があるとしたら、
|
11
|
+
省略されたselectイベントに問題がある可能性が高いと思われます。
|
12
|
+
let sample = document.getElementById('second_zip'); の位置が悪いなど
|
13
|
+
もう一つ気になったのは、document.getElementbyIdとbがBじゃなかったことくらいです。
|
14
|
+
|
15
|
+
```HTML
|
16
|
+
<!DOCTYPE html>
|
17
|
+
<html lang="ja">
|
18
|
+
|
19
|
+
<head>
|
20
|
+
<meta charset="UTF-8">
|
21
|
+
<title>test</title>
|
22
|
+
</head>
|
23
|
+
|
24
|
+
<body>
|
25
|
+
<input id="first_zip" type="text" name="1人目の郵便番号" value="test">
|
26
|
+
<input id="second_zip" type="text" name="2人目の郵便番号">
|
27
|
+
<script>
|
28
|
+
let sample = document.getElementById('second_zip');
|
29
|
+
if (!sample.value) {
|
30
|
+
sample.value = document.getElementById('first_zip').value;
|
31
|
+
}
|
32
|
+
</script>
|
33
|
+
</body>
|
34
|
+
|
35
|
+
</html>
|
36
|
+
```
|