質問編集履歴

4

質問タイトルの変更

2019/06/25 05:53

投稿

Yuto921
Yuto921

スコア11

test CHANGED
@@ -1 +1 @@
1
- YoutubeAPIを使ったVideoGallary作りたい。
1
+ JavaScriptの要素の値取得して、書き換えるには?
test CHANGED
@@ -188,6 +188,8 @@
188
188
 
189
189
  };
190
190
 
191
+
192
+
191
193
  cosole.logで確認したところ、変数のcommandにフォームで入力した値が入ってないことが分かりました。
192
194
 
193
195
  formボタンが押されたら、フォームの入力値を変数commandに代入したいのですが、どのようにしたらいいのでしょうか?

3

やりたいことの追加

2019/06/25 05:53

投稿

Yuto921
Yuto921

スコア11

test CHANGED
File without changes
test CHANGED
@@ -172,7 +172,25 @@
172
172
 
173
173
  以上のようなコードで書いてみたのですが、うまくいきません。
174
174
 
175
+
176
+
177
+ *追記
178
+
179
+ let command;
180
+
181
+ document.getElementById('form').onsubmit = function() {
182
+
183
+ command = document.getElementById('form').word.value;
184
+
185
+ console.log(command);
186
+
175
- どこが間違っているのでしょうか?
187
+ return false;
188
+
189
+ };
190
+
191
+ cosole.logで確認したところ、変数のcommandにフォームで入力した値が入ってないことが分かりました。
192
+
193
+ formボタンが押されたら、フォームの入力値を変数commandに代入したいのですが、どのようにしたらいいのでしょうか?
176
194
 
177
195
 
178
196
 

2

jsファイルの修正

2019/06/25 01:41

投稿

Yuto921
Yuto921

スコア11

test CHANGED
File without changes
test CHANGED
@@ -38,9 +38,9 @@
38
38
 
39
39
  <h2>検索ワード</h2>
40
40
 
41
- <form action="" method="post">
41
+ <form action="" id="form">
42
42
 
43
- <input type="text" id="form" name="text">
43
+ <input type="text" id="form" name="word">
44
44
 
45
45
  <input type="submit" id="buttonid" value="検索">
46
46
 
@@ -70,17 +70,17 @@
70
70
 
71
71
  ```ここに言語を入力
72
72
 
73
- let command ;
73
+ let command;
74
74
 
75
- $("buttonid").on('click',function(){
75
+ document.getElementById('form').onsubmit = function() {
76
76
 
77
- command = document.getElementById('form');
77
+ command = document.getElementById('form').word.value;
78
78
 
79
- return command;
79
+ console.log(command);
80
80
 
81
- });
81
+ return false;
82
82
 
83
- console.log(command);
83
+ };
84
84
 
85
85
  // リクエストパラメータのセット
86
86
 

1

index.htmlのformタグの修正とapp.jsの修正

2019/06/24 13:50

投稿

Yuto921
Yuto921

スコア11

test CHANGED
File without changes
test CHANGED
@@ -11,6 +11,8 @@
11
11
  ![イメージ説明](4cf912dfe7cad59c50d04627f028a864.png)
12
12
 
13
13
 
14
+
15
+ index.html
14
16
 
15
17
  ```ここに言語を入力
16
18
 
@@ -36,9 +38,13 @@
36
38
 
37
39
  <h2>検索ワード</h2>
38
40
 
41
+ <form action="" method="post">
42
+
39
43
  <input type="text" id="form" name="text">
40
44
 
41
- <button id="buttonid">検索</button>
45
+ <input type="submit" id="buttonid" value="検索">
46
+
47
+ </form>
42
48
 
43
49
  </section>
44
50
 
@@ -58,15 +64,23 @@
58
64
 
59
65
  ```
60
66
 
67
+
68
+
69
+ app.js
70
+
61
71
  ```ここに言語を入力
62
72
 
73
+ let command ;
74
+
63
- $("buttonid").click(function(){
75
+ $("buttonid").on('click',function(){
64
76
 
65
77
  command = document.getElementById('form');
66
78
 
67
- cosloe.log(command);
79
+ return command;
68
80
 
69
81
  });
82
+
83
+ console.log(command);
70
84
 
71
85
  // リクエストパラメータのセット
72
86