お世話になっております。
javascriptにて子ウィンドウから親ウィンドウに値の受渡しについてご教示下さい。
parent.htm
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <script> function openChild(f){ window.open("child.htm","_blank", "width=200,height=200"); } </script> <form> チェックボックスデータ:<input id="hoge"><br /> テキストデータ:<input id="hoge2"><br /> <input type="button" onclick="openChild(this.form)" value="子ウィンドを開く"> </form> </body> </html>child.htm
<html> <head> <title>子ウィンドウ</title> </head> <body> <script> function sendtoParent(f){ var str=""; for (var i=0;i<f.length;i++){ if(f[i].type=="checkbox" && f[i].checked){ str+=(str==""?"":",")+f[i].value; } } opener.document.getElementById("hoge").value=str; } </script> <form> <input type="checkbox" id="data1" value="データ1"><label for="data1">データ1</label> <input type="checkbox" id="data2" value="データ2"><label for="data2">データ2</label> <input type="checkbox" id="data3" value="データ3"><label for="data3">データ3</label><br /> <input id="txtdata"> <input type="button" onclick="sendtoParent(this.form)" value="親に送る"> </form> </body> </html>上記のような親ウィンドウであるparent.htmと、子ウィンドウとなるchild.htmがあります。
子ウィンドウを開き、チェックボックスにチェックを入れたものは、親ウィンドウの<input id="hoge">に値が反映されますが、同時に子ウィンドウの<input id="txtdata">に入力した値も<input id="hoge2">に反映させたいと思っていますが、なかなか出来ずに立ち止まってしましました。
お忙しいなか恐縮ですがご指導のほどお願い出来れば幸いです。
宜しくお願い致します。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/03/29 01:50
2015/03/29 02:17
2015/03/29 03:05