admin管理员组文章数量:1391969
I am creating an HTML form. Inside it, there is one input box, for which I want to create a popup that provides a textarea. This would give the user more space to enter a larger block of text. My current code enables the child window (pop-up) to send the entered text back to the parent. However, I also need to have the parent window send the current text to the textarea in the child window. I'd appreciate some help.
I created a simplified version, with just one input box, for the purpose of this discussion.
Here is the code from the parent:
<HTML><HEAD></HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
function openChild(file,window) {
childWindow=open(file,window,'resizable=no,width=200,height=400');
if (childWindow.opener == null) childWindow.opener = self;
}
//--></SCRIPT>
<BODY>
<FORM NAME="parentForm">
<INPUT TYPE="button" VALUE="Open child" onClick="openChild('examplejs2.html','win2')">
<BR><INPUT NAME="pf1" TYPE="TEXT" VALUE="">
</FORM></BODY></HTML>
Here is the code from the child window (pop-up):
<HTML><HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
function updateParent() {
opener.document.parentForm.pf1.value = document.childForm.cf1.value;
opener.document.parentForm.pf2.value = document.childForm.cf2.value;
if (document.childForm.cf3[0].checked)
opener.document.parentForm.pf3[0].checked = true;
if (document.childForm.cf3[1].checked)
opener.document.parentForm.pf3[1].checked = true;
self.close();
return false;
}
//--></SCRIPT>
</HEAD><BODY>
<FORM NAME="childForm" onSubmit="return updateParent();">
<BR><INPUT NAME="cf1" TYPE="TEXT" VALUE="">
</FORM></BODY></HTML>
I am creating an HTML form. Inside it, there is one input box, for which I want to create a popup that provides a textarea. This would give the user more space to enter a larger block of text. My current code enables the child window (pop-up) to send the entered text back to the parent. However, I also need to have the parent window send the current text to the textarea in the child window. I'd appreciate some help.
I created a simplified version, with just one input box, for the purpose of this discussion.
Here is the code from the parent:
<HTML><HEAD></HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
function openChild(file,window) {
childWindow=open(file,window,'resizable=no,width=200,height=400');
if (childWindow.opener == null) childWindow.opener = self;
}
//--></SCRIPT>
<BODY>
<FORM NAME="parentForm">
<INPUT TYPE="button" VALUE="Open child" onClick="openChild('examplejs2.html','win2')">
<BR><INPUT NAME="pf1" TYPE="TEXT" VALUE="">
</FORM></BODY></HTML>
Here is the code from the child window (pop-up):
<HTML><HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
function updateParent() {
opener.document.parentForm.pf1.value = document.childForm.cf1.value;
opener.document.parentForm.pf2.value = document.childForm.cf2.value;
if (document.childForm.cf3[0].checked)
opener.document.parentForm.pf3[0].checked = true;
if (document.childForm.cf3[1].checked)
opener.document.parentForm.pf3[1].checked = true;
self.close();
return false;
}
//--></SCRIPT>
</HEAD><BODY>
<FORM NAME="childForm" onSubmit="return updateParent();">
<BR><INPUT NAME="cf1" TYPE="TEXT" VALUE="">
</FORM></BODY></HTML>
Share
Improve this question
asked Apr 19, 2016 at 19:49
Sarah C. CorriherSarah C. Corriher
551 gold badge1 silver badge12 bronze badges
2 Answers
Reset to default 2I ended up throwing most of the work in the question away, and not using a distinct window (but still using a pop-up). Here is the HTML:
<input type="text" id="text-source" value="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea modo consequat."/>
<button id="edit">Edit</button>
<div id="edit-popup" style="display: none">
<textarea id="text-edit"/>
</div>
Here is the javascript that I settled upon:
$("#edit").click(function() {
$("#text-edit").val($("#text-source").val());
$("#edit-popup").dialog({
height: 400,
width: 600,
modal: true,
buttons: {
"Close": function () {
$("#text-source").val($("#text-edit").val());
$(this).dialog("close");
}
}
});
});
See it in action: https://jsfiddle/sazzy/5m621rLa/
I see no textarea in your child form, but assuming your childwindow has:
<textarea name="cf1"></textarea>
After opening the child window, you may need to wait for it to be ready/loaded, then do this:
var myVal = document.getElementsByName("pf1")[0].value;
childWindow.document.getElementsByName("cf1")[0].value = myVal;
本文标签: javascriptPopup for Editing Input FieldStack Overflow
版权声明:本文标题:javascript - Pop-up for Editing Input Field - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744712255a2621198.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论