window.opener.document-阿里云开发者社区

开发者社区> 开发与运维> 正文

window.opener.document

简介:
travisbrown (TechnicalUser)
10 May 07 1:07
I'm trying to set the value/innerHTML of a text area in a parent page from a popup. Is there anything obviously wrong with the script below? The first two elements are passing back properly. job_desc is not working with either innerHTML or value. I've double-checked that the id names are correct, and I'm not getting any errors in the FF error console.

CODE

<script type="text/javascript">
function transferTemplate(id) {
    window.opener.document.getElementById('job_mini_desc').value = document.getElementById('job_mini_desc_' + id).value;
    window.opener.document.getElementById('job_title').value = document.getElementById('job_title_' + id).value;
    window.opener.document.getElementById('job_desc').value = document.getElementById('job_desc_' + id).value;
    //window.opener.document.getElementById('job_desc').innerHTML = document.getElementById('job_desc_' + id).value
    //self.close();
}
</script>

The target element is 

CODE

<textarea name="job_desc" id="job_desc">
  </textarea>
Tek-Tips Forums is Member Supported. Click Here to donate.
monksnake (Programmer)
10 May 07 9:28
Where is this element defined in your HTML?:

CODE

document.getElementById('job_desc_' + id).value


Can you post that element along with the call to the function transferTemplate?

I don't see anything immediately wrong, but I also don't see all the factors involved.

monkeysnake <.

travisbrown (TechnicalUser)
10 May 07 10:18
Here's the popup html

CODE


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Employment Templates</title>
<script type="text/javascript">
function transferTemplate(id) {
    window.opener.document.getElementById('job_mini_desc').value = document.getElementById('job_mini_desc_' + id).value;
    window.opener.document.getElementById('job_title').value = document.getElementById('job_title_' + id).value;
    window.opener.document.getElementById('job_desc').value = document.getElementById('job_desc_' + id).value;
    //window.opener.document.getElementById('job_desc').innerHTML = document.getElementById('job_desc_' + id).value
    //self.close();
}
</script>
<script type="text/javascript" src="../_scripts/common.js"></script>
<link href="admin.css" rel="stylesheet" type="text/css" media="screen">
</head>

<body>
<ul>

    <li id="job_36"><a href="javascript:transferTemplate(36);" id="" >ASSISTANT DISPATCHER W/CLASS 1</a>
    <input id="job_title_36" type="hidden" value="ASSISTANT DISPATCHER W/CLASS 1" />
    <input id="job_mini_desc_36" type="hidden" value="Required in our Edmonton Branch" />
    <input id="job_desc_36" type="hidden" value="test 123" />
    <a href="javascript:sndReq('process_job_template.asp?job_template_id=36&mode=delete','job_36');">delete</a>
    </li>

    <li id="job_37"><a href="javascript:transferTemplate(37);" id="" >HOUSEHOLD GOODS RECEIVER</a>
    <input id="job_title_37" type="hidden" value="HOUSEHOLD GOODS RECEIVER" />
    <input id="job_mini_desc_37" type="hidden" value="Required in our Edmonton Freight Division" />
    <input id="job_desc_37" type="hidden" value="&lt;p&gt;We are currently seeking a summer&amp;nbsp;household goods receiver&amp;nbsp;in our freight&amp;nbsp;division to commence June 1st, 2007.&amp;nbsp; This position will end in August / September.&lt;/p&gt;&lt;h2&gt;Skills and duty requirements include:&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;Professionalism in customer service &lt;/li&gt;&lt;li&gt;Excellent organization and planning abilities&lt;/li&gt;&lt;li&gt;Working with a partner to use dollies and straps to move very heavy items&lt;/li&gt;&lt;li&gt;Breaking down of packing material, folding pads, and other general warehouse duties including..." />
    <a href="javascript:sndReq('process_job_template.asp?job_template_id=37&mode=delete','job_37');">delete</a>
    </li>

</ul>
</body>
</html>
monksnake (Programmer)
10 May 07 10:52
I just set up a sample that uses your popup window and it worked perfectly.

Here is what I got for your function (untouched, just removed comments):

CODE

function transferTemplate(id) {
    window.opener.document.getElementById('job_mini_desc').value = document.getElementById('job_mini_desc_' + id).value;
    window.opener.document.getElementById('job_title').value = document.getElementById('job_title_' + id).value;
    window.opener.document.getElementById('job_desc').value = document.getElementById('job_desc_' + id).value;
    self.close();
}

Here is my test HTML file that calls the popup:

CODE

<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
   <span id="job_mini_desc"</span>
   <span id="job_title"></span>
   <textarea id="job_desc"></textarea>
   <input type="button" onclick="window.open('test.html', 'popup', 'height=200, width=300')" value="CLICK" /> 
</body>
</html>

The only thing I can think of why your code doesn't work is you may have more than one id = "job_desc"

 

本文转自kenty博客园博客,原文链接http://www.cnblogs.com/kentyshang/archive/2007/05/29/764011.html如需转载请自行联系原作者

kenty

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章