Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert into textarea from popup

Status
Not open for further replies.

varnix

Programmer
Jan 7, 2002
94
US
I know how to use javascript from a pop-up window to insert data into a straight text field in a form.

But I would like to be able to have a textarea field in my form with an optional pop-up window that my users can click on a graphic within that window that will then place a unique identifier for that graphic into the textarea field where the cursor was last positioned.

Is there a way to do this?
 
I can help you with some of this...

The following will take a value from your pop-up window and write it to a textbox in the main window. As you will notice "onblur" is the event that triggers this operation. For your purposes, you might trigger the action with "onclick" applied to your images.

Here is the code for the pop-up window:

<html>
<body>
<script language=&quot;javaScript&quot;>
function writeToOpener(obj)
{
opener.document.getElementById('thisTxtBox').value = obj.value;
}
</script>
<form method=&quot;POST&quot;>
<p><input type=&quot;text&quot; id=&quot;txtBox&quot; size=&quot;20&quot; onblur=&quot;writeToOpener(this)&quot;></p>
</form>
</body>
</html>

Here is the code for the &quot;main&quot; window:

<html>
<body>
<script language=&quot;javascript&quot;>
function openWin()
{
var newWin = open('C:\\pop.htm', 'myWin');
var msg = newWin.document.getElementById('txtBox').value;
document.getElementById('thisTxtBox').value = msg;
}
</script>
<p onclick=&quot;openWin()&quot;>CLICK HERE</p>
<p><input type=&quot;text&quot; size=&quot;30&quot; id=&quot;thisTxtBox&quot;>
</body>
</html>

As for inserting the text into a textarea in the spot last occupied by the cursor, that was covered in this thread:
thread216-549806
Note that this will probably only work in IE.

Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top