ポップアップしてアドレスの表を表示し、ユーザーがアドレスの1つをクリックしてその情報を親に送り返すウィンドウを作成しようとしています。私の関数は現在次のようになっています(elseセクションは私が問題を抱えている場所です):
function ups_address_validation(address1, address2, city, state, zip)
{
var address = new Object;
address.address1 = address1.value;
address.address2 = address2.value;
address.city = city.value;
address.state = state.value;
address.zip = zip.value;
var data = {address: address};
var info = ups_api('validate_address', data);
if (info.hasOwnProperty('ValidAddressIndicator'))
{
$("#" + address1.field).val(info.Candidate.AddressKeyFormat.AddressLine[0]);
$("#" + address2.field).val(info.Candidate.AddressKeyFormat.AddressLine[1]);
$("#" + city.field).val(info.Candidate.AddressKeyFormat.PoliticalDivision2);
$("#" + state.field).val(info.Candidate.AddressKeyFormat.PoliticalDivision1);
$("#" + zip.field).val(info.Candidate.AddressKeyFormat.PostcodePrimaryLow + '-' + info.Candidate.AddressKeyFormat.PostcodeExtendedLow);
}
else
{
var candidates = info.Candidate;
var popup = window.open('', 'Addresses', 'width=850, height=350, scrollbars=1' );
var html = "<head>" +
"<link rel='stylesheet' type='text/css' href='css/style.css' media='screen'></link>" +
"<link type='text/css' href='/public/utilities/jquery/css/smoothness/jquery-ui-1.8.22.custom.css' rel='stylesheet'></link>" +
"<script type='text/javascript' src='/public/utilities/jquery/js/jquery-1.7.2.min.js'></script>" +
"<script type='text/javascript'> $(document).ready(function(){$('td').click(function(){alert('clicked');})});});</script>" +
"</head><body>" +
"<div class='wrapper' style='width: 800; background-color: #fff'><div class='content' style='width: 800'>" +
"<div class='module_header'>Confirmed Addresses</div><table class='lookup_table' style='width: 800'><tr><th>Address1</th><th>Address2</th><th>City</th><th>State</th><th>Zip</th></tr>";
var i = 0;
for (var i in candidates)
{
var row = (i %2)? 'alt': '';
html += "<tr class='"+row+"'>";
if (info.Candidate[i].AddressKeyFormat.AddressLine instanceof Object)
{
for (var p in info.Candidate[i].AddressKeyFormat.AddressLine)
{
html += "<td>" + info.Candidate[i].AddressKeyFormat.AddressLine[p] + "</td>";
}
}
else
{
html+= "<td>" + info.Candidate[i].AddressKeyFormat.AddressLine + "</td><td></td>";
}
html += "<td>" +
info.Candidate[i].AddressKeyFormat.PoliticalDivision2 +
"</td><td>" +
info.Candidate[i].AddressKeyFormat.PoliticalDivision1 +
"</td><td>" +
info.Candidate[i].AddressKeyFormat.PostcodePrimaryLow + "-" + info.Candidate[i].AddressKeyFormat.PostcodeExtendedLow +
"</td></tr>";
}
html += "</table><div class='module_header'>Submitted Address</div><table class='lookup_table' style='width: 800'><tr><th>Address1</th><th>Address2</th><th>City</th><th>State</th><th>Zip</th></tr>";
html += "<tr><td>" + address1.value + "</td><td>" + address2.value + "</td><td>" + city.value + "</td><td>" + state.value + "</td><td>" + zip.value + "</td><tr></table>";
html += "</div></div></body>";
popup.document.write(html);
$(popup.document).ready(function(){
$('td').click(function(){alert('clicked');});
});
}
}
そのデータを親ウィンドウに送り返す関数を使用して、各テーブル行に onClick イベントを追加したいと考えています。ただし、次のことを試しました。
$(popup.document).ready(function(){ $('td').click(function(){ alert('clicked');});});
またはスクリプトセクションを使用して
テーブルから情報を返すことができるように、onclickイベントを子ウィンドウタグに(子ウィンドウに渡すか、親から設定することにより)どのようにすればよいですか。