View Full Version : write parent textfield value to child span ID tags...
hi guys
I've exhausted my usual friends with this problem, so I've arrived at ur doorstep in search of some answers.
The purpose of this script is the same as a 'preview post' we get in forums. Users add text to a textarea then format it using schmick buttons to insert tags.
The function I'm using to set up the preview pop-up is:
(parent textfield in Q'n is ..postContent.content.value)
function launch(newURL, newName, newFeatures, orgName) {
var remote = open(newURL, newName, newFeatures);
if (remote.opener == null)
remote.opener = window;
remote.opener.name = orgName;
return remote;
}
function launchPreview() {
window.open("reply_preview_pop.asp", "PreviewContent", "height=400,width=600,yada yada yada,"contribText");
}
This function is called by the preview button and the preview window opens up fine.
However the problem lies with my being able to insert the text from the parent textfield into some span tags of the child.
I've tried far too many various functions, none seem to work and I'm not sure if Im targeting the opener's textfield ID correctly either.
The POS script in the child window looks like this atm.. it's changed considerably over the last 2 days when I feel like nagging it.
(child target is window(?).insertHere.value)
function display(NewCode) {
document.insertHere.value+=NewCode
}
function tfer() {
AddTxt=window.contribText.postContent.Content.value
display(AddTxt)
}
function start() {
window.focus()
tfer()
}
and it called by an onLoad="start()" in the head tags.
I've ID'd some span tags further down the child page as "insertHere" :-|
The site's using asp/javascript and I wont use cookies to solve this problem, nor session variables [in asp]. Im sure the idea behind this script is sound, I just dont know the syntax.
p.s. innerHTML is out since it's IE specific, I'd prefer a cross browser solution...
thx in advance guys.
beetle
01-23-2003, 04:28 PM
I have a method for doing this that varies quite a bit from how you are attempting it.
Here's the 'parent' page<html>
<head>
<title>This is the parent page</title>
<script type="text/javascript">
function submitForm( f, pview )
{
if ( pview ) // preview
{
var preview = window.open( "about:blank", "preview", "height=400,width=600" );
f.action = "reply_preview_pop.asp";
f.target = "preview";
f.method = "get";
f.submit();
}
else // submit form for real
{
f.action = "yourFormHandlingPage.asp";
f.target = "_self";
f.method = "post";
f.submit();
}
}
</script>
</head>
<body>
<form action="" method="" target="" >
<input type="text" name="messageBody" />
<br />
<input type="button" value="Preview" onclick="submitForm( this.form, 1 );" />
<input type="button" value="Submit" onclick="submitForm( this.form, 0 );" />
</form>
</body>
</html>ANd here is the popup page<html>
<head>
<title>This is the popup page</title>
<script type="text/javascript">
function GetVars( def )
{
this._def_ = def;
var query, queries = top.location.search.substring(1).split( /\&/ );
for ( var i=0; (query = queries[i]); i++ )
{
query = query.split( /\=/ );
this[query[0]] = ( typeof query[1] == 'undefined' ) ? def : unescape(query[1]).replace( /\+/g, " " );
}
}
GetVars.prototype.assign = function( key )
{
return ( this.exists( key ) ) ? this[key] : this._def_;
}
GetVars.prototype.exists = function( key )
{
return ( typeof this[key] != 'undefined' );
}
function setText()
{
var g = new GetVars( '' );
document.getElementById( 'bodyText' ).firstChild.nodeValue = g.assign('messageBody');
}
</script>
</head>
<body onload="setText()">
<span id="bodyText"></span>
</body>
</html>
thx for the reply beetle..
if I understand your method, the entire value of the parent textfield is sent to the child window as part of a query string (method="get")?
Then the child window rips that value and equates it to the getElementById( 'body text') for the span...
This being the case, I have a problem with your solution; the parent textfield could contain in excess of 2000 words, depending on the content being submitted. This make a doosie of a string yes ? Will that not create more problems...
beetle
01-23-2003, 10:39 PM
I see, that certainly makes sense. GET data can be no longer than 512 bytes, if I remember correclty (maybe 1024)
So, moving on, here's some code/pseudo code to get you going in the right directionvar preview = window.open("somepage.asp","preview","features");in the popupwindow.onload = function()
{
document.getElementById('bodyText').firstChild.nodeValue = top.opener.document.myForm.messageBody.value;
}Wow, easy, eh?
heh, that was my original thinking except for using getElementById('bodyText').firstChild.nodeValue because the opener property sets a reference to the window that created it - hence precluding all that DOM stuff....
both lines;
document.getElementById('setText').firstChild.nodeValue = top.opener.document.postContent.Content.value;
and
document.setText.value = window.opener.postContent.Content.value
don't work :( been there two days ago. Im sure the solution lies in connecting the dots witn the proper names on both sides of that simple lil '=' ...
finally I got this bugger to work, of sorts... but the text in the child window is char for char - it ignores html tags and just displays them...
how can I get the child window to format the text as required by the html tags written in the parent text field?
parent function;
function previewText() {
txtPreview = window.open("reply_preview_pop.asp","myPreview","height=450,width=600,alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscre en=0,hotkeys=1,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0,z-lock=0")
txtPreview.opener = self
}
and the child function;
function start() {
self.document.getElementById('insertHere').firstChild.nodeValue = window.opener.document.postContent.Content.value;
window.focus()
}
any ideas fellas ?
glenngv
01-27-2003, 03:19 AM
Originally posted by meth
p.s. innerHTML is out since it's IE specific, I'd prefer a cross browser solution...
for whatever it's worth, innerHTML also works with NS6 and Mozilla :)
yeah - Ive since caught an article discussing innerHTML and one of the newgroup members had done the research into all browsers supporting it...
Microsoft Internet Explorer 4+
Microsoft Internet Explorer 5 Mac
Opera 7+ (November 2002)
Mozilla M17+
Netscape 6+
Konqueror 2.2+
IceStorm 5.
iCab 2.x+
MS Pocket IE 3.x+
dev'-x/innerHTML (http://www.developer-x.com/content/innerhtml/)
k - for the sake of some closure on this thread, I work out a solution that avoids cookies, strings and having to write all the html code for the window.open file in the parent function.
After days of surfing and experimenting I recon its the simplest solution I coulda nutted out...
parent function
function previewContent() {
txtPreview = window.open("reply_preview_pop.asp","myPreview","height=450,width=600,blah,blah,blah)
txtPreview.opener = self
}
called by form button (not a href'ed image button "onClick:JS call...)
ie.<input name="Preview" type="button" id="Preview" value="Preview" onClick="previewContent()">
child function
header
<script language="JavaScript" type="text/javascript">
<!--
var insertContent = window.opener.document.postContent.Content.value;
-->
</script>
<body blah blah onLoad="window.focus()">
at insertion point in body (inbetween td tags in this case)
<script language="JavaScript" type="text/javascript">
<!--
document.write(insertContent)
-->
</script>
close preview pop-up with link
<a href="JavaScript:onClick=self.close()">close</a>
janetb
04-26-2006, 07:27 PM
Meth,
I'm trying to do approximately the same thing and wanted to steal your hard work, but I know nada about JavaScript and I'm getting an 'undefined' error on the child page I'm wanting to display. Mind helping out?
Thanks,
Janet
Parent: (formPop.html)
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function previewContent() {
txtPreview = window.open("testPop.asp","myPreview","height=450,width=600")
txtPreview.opener = self
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="text1">
<input name="Preview" type="button" id="Preview" value="Preview" onClick="previewContent()">
</form>
</body>
</html>
Child:testPop.asp
<html>
<head>
<title>Test</title>
<script language="JavaScript" type="text/javascript">
<!--
var insertContent = window.opener.document.postContent.Content.value;
-->
</script>
</head>
<body onLoad="window.focus()">
<table><tr><td>
<script language="JavaScript" type="text/javascript">
<!--
document.write(insertContent)
-->
</script>
<br /></td></tr></table>
<a href="javascript:onClick=self.close()">close</a>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.