Updating a textbox from a popup window?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
anomaly
Forum Newbie
Posts: 15
Joined: Mon Oct 21, 2002 9:45 pm

Updating a textbox from a popup window?

Post by anomaly »

I have a textarea in a php page, and I would like to have a button next to this textarea that pops up a window. Inside this window the user will type in some information, and I would like to pass this information(after the script formats it) to the textarea(without erasing the info already in the textarea).

Is this possible?

It would be very useful for making links, if the user could just enter the link information and this script could make the a href tag for them.

Thanks.
anomaly
Forum Newbie
Posts: 15
Joined: Mon Oct 21, 2002 9:45 pm

Post by anomaly »

bump
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if a window is opened due to the action of another window the object opener is a reference to the opening window.
The (maybe) tricky part is to propagate the target-object to the new window.
Maybe a little overkill -but hey- it's mainly a php-board ;)

Code: Select all

<?php
if (isset($_GETї'mode']) && $_GETї'mode'] == 'inputWindow')
{
?><html><head><script language="JavaScript">
	function writeBack()
	{
		oSource = document.getElementById("inputField");
		oTarget = opener.document.getElementById("<?php echo $_GETї'target'] ?>");
		oTarget.value += oSource.value;
		self.close();
	}
</script></head><body>
	<input id="inputField" />
	<button onClick="writeBack();">done.</button>
</body></html><?php
}
else
{
?><html><head><script langeuage="JavaScript">
	function createPopup(sTargetId)
	{
		window.open("<?php echo $_SERVERї'PHP_SELF']; ?>?mode=inputWindow&target="+sTargetId,"inputWindow","width=310,height=150,left=50,top=50");
	}
</script></head><body>
	<form >
		<textarea id="ta1">default</textarea>
		<button OnClick="createPopup('ta1');">enter new text</button>
	</form>
</body></html>
<?php } ?>
tested with IE6 and phoenix 0.4
Post Reply