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

質問編集履歴

3

最終的な解決のコードを追記しました。

2018/06/08 07:52

投稿

mari.rinn
mari.rinn

スコア296

title CHANGED
File without changes
body CHANGED
@@ -31,4 +31,35 @@
31
31
  2件以上になった場合、一番最新のものだけが、blankの別ウインドウが立ち上がり、それ以降のものはクリックしても何も反応がありません。
32
32
 
33
33
  これを各データに対して同じように正しく行うにはどうしたらよいでしょうか?
34
- よろしくお願いいたします。
34
+ よろしくお願いいたします。
35
+
36
+ 【追記】
37
+ ご回答いただいた方法でうまく出来ましたので最終的なコードを一応記載しておきます。
38
+
39
+ ```PHP
40
+ print " <table><tr>
41
+ <td><div>" .$e_name. "</div></td>
42
+ <td><div>" .$cus. "</div></td>
43
+ <td><div>
44
+ <form action='edit.php' method='POST' target='edit" .$cid. "'>
45
+ <input type='hidden' name='ce_id' value='".$cid."'>
46
+ <input type='hidden' name='ce_nam' value='".$cus."'>
47
+ <input type='hidden' name='ce_enam' value='".$e_name."'>
48
+ <input type='hidden' name='ce_body' value='".$code_body."'>
49
+ <input type='hidden' name='ce_fnam' value='".$code_name."'>
50
+ <a href='javascript:void(0)' class='cedit'>" .$code_name. "</a></form>
51
+ </div></td></tr></table>";
52
+ ```
53
+
54
+ ```jQuery
55
+ $(function(){
56
+ $("a.cedit").on('click',function(){
57
+ var form = $(this).parent('form');
58
+ var target = form.attr('target');
59
+ window.open("about:blank",target,"top=100,left=150,width=500,height=500,scrollbars=1,location=0,menubar=0,toolbar=0,status=1,directories=0,resizable=1");
60
+ form.submit();
61
+ return false;
62
+ }
63
+ });
64
+ });
65
+ ```

2

ご回答頂いた内容に基づいてコードの変更を行いましたので修正しました。

2018/06/08 07:52

投稿

mari.rinn
mari.rinn

スコア296

title CHANGED
File without changes
body CHANGED
@@ -5,28 +5,27 @@
5
5
  <td><div>" .$e_name. "</div></td>
6
6
  <td><div>" .$cus. "</div></td>
7
7
  <td><div>
8
- <form action='edit.php' method='POST' name='toedit'>
8
+ <form action='edit.php' method='POST'>
9
9
  <input type='hidden' name='ce_id' value='".$cid."'>
10
10
  <input type='hidden' name='ce_nam' value='".$cus."'>
11
11
  <input type='hidden' name='ce_enam' value='".$e_name."'>
12
12
  <input type='hidden' name='ce_body' value='".$code_body."'>
13
13
  <input type='hidden' name='ce_fnam' value='".$code_name."'>
14
- <a href='javascript:toedit.submit()' id='cedit'>" .$code_name. "</a></form>
14
+ <a href='javascript:void(0)' class='cedit'>" .$code_name. "</a></form>
15
15
  </div></td></tr></table>";
16
16
 
17
17
  ```
18
18
  ``` jQuery
19
19
  $(function(){
20
- $("#cedit").on('click',function(){
20
+ $("a.cedit").on('click',function(){
21
21
  window.open("about:blank","edit","top=100,left=150,width=500,height=500,scrollbars=1,location=0,menubar=0,toolbar=0,status=1,directories=0,resizable=1");
22
- document.toedit.target = "edit";
22
+ $(this).parent('form').target = "edit";
23
- document.toedit.action = "edit.php";
23
+ $(this).parent('form').action = "code_edit.php";
24
- document.toedit.method = "post";
24
+ $(this).parent('form').method = "post";
25
- document.toedit.submit();
25
+ $(this).parent('form').submit();
26
26
  return false;
27
- }
28
27
  });
29
- });
28
+ });
30
29
  ```
31
30
  これで、リスト表示部分のデータが1件だけの場合は問題なく別ウインドウが表示される(POST送信したものも問題なく処理されている)のですが、
32
31
  2件以上になった場合、一番最新のものだけが、blankの別ウインドウが立ち上がり、それ以降のものはクリックしても何も反応がありません。

1

上部コードの言語をhtmlと記述していましたが、正しくはPHPでしたので、言語名を修正し、コードに、リスト表示部分の頭からを付け足しました。

2018/06/08 03:09

投稿

mari.rinn
mari.rinn

スコア296

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,10 @@
1
1
  mySQLから取り出したデータ(データがあるだけリスト表示)にリンクを貼って、そのリンクをクリックすると別ウインドウが開き、同時に、hiddenでPOST送信したデータもそこに送信されるようにしたいです。
2
2
 
3
- ``` html
3
+ ``` php
4
+ print " <table><tr>
5
+ <td><div>" .$e_name. "</div></td>
6
+ <td><div>" .$cus. "</div></td>
7
+ <td><div>
4
8
  <form action='edit.php' method='POST' name='toedit'>
5
9
  <input type='hidden' name='ce_id' value='".$cid."'>
6
10
  <input type='hidden' name='ce_nam' value='".$cus."'>
@@ -8,6 +12,8 @@
8
12
  <input type='hidden' name='ce_body' value='".$code_body."'>
9
13
  <input type='hidden' name='ce_fnam' value='".$code_name."'>
10
14
  <a href='javascript:toedit.submit()' id='cedit'>" .$code_name. "</a></form>
15
+ </div></td></tr></table>";
16
+
11
17
  ```
12
18
  ``` jQuery
13
19
  $(function(){
@@ -17,6 +23,7 @@
17
23
  document.toedit.action = "edit.php";
18
24
  document.toedit.method = "post";
19
25
  document.toedit.submit();
26
+ return false;
20
27
  }
21
28
  });
22
29
  });