Click to See Complete Forum and Search --> : Send info to Popup, then submit back to particualr control


timcadieux
11-23-2002, 04:50 PM
Ok, i have a variable that i set to a textarea. If my client wants to edit the content, i want them to be able to hit my Edit button and the content gets displayed in my PopUp Editor, i have that much working.. What i want is for my Save button on my Popup to send the changed info back to the original TextArea on my original page, how can i do this? What i have so far is pasted below.

Also, i may have a number of different TextArea on one page, i want to be able to add this Edit Button next to each one and always have the Content return back to the correct one.

Help!

<center>
<FORM name=exampleform id="data">
<P> <textarea id="data" name="data" cols="50" rows="25"><%= sWelcome %></textarea>
<input type="button" value="Edit" onClick="edit()"></P>
</FORM>
</center>
</body>
<script language="JavaScript">
function edit() {
var edit={}
edit.src = data.innerHTML;
edit.styledata=document.styleSheets
window.showModalDialog("popup_editor.html", edit,"dialogWidth:800px;dialogHeight:600px;help:no;status:no;scroll:no;resizable:yes;")
}
</script>

MikeOS
11-23-2002, 07:15 PM
Here is what I came up with, it may not be the best way as my javascript is a bit rusty, but it works. Here is the page that contains the textarea, I added another textarea to show how it works with more than one (although it is much easier with just one).

<html>
<body>
<head>
<script language="JavaScript">
var thedata;
var newwin;
var thenumber;
function edit(textarea)
{
if (textarea == 0)
{
thedata = document.exampleform.data.value
thenumber = 0

}
else if (textarea == 1)
{
thedata = document.exampleform.data1.value
thenumber = 1
}
newwin = window.open("popup_editor.html","","width=800,height=600,resizable")
}
</script>
</head>
<center>
<FORM name="exampleform">
<P> <textarea id="data" name="data" cols="50" rows="25"></textarea>
<input type="button" value="Edit" onclick="edit(0)"></P>
<P> <textarea id="data1" name="data1" cols="50" rows="25"></textarea>
<input type="button" value="Edit" onclick="edit(1)"></P>
</FORM>
</center>
</body>
</html>

You'll note three variables have been declared. thedata will get and store the data held in the appropriate textarea. newwin stores the new window object (the pop up window), thenumber tells me which textarea was clicked. You can see the edit() function in each call passes a number, this tells me which textarea was clicked, so I assign this number to the thenumber variable as I'll need it in the popup window. Note I used if, else if, instead of if, else as I thought you may be adding more textareas. Here is the popup window code:

<html>
<head>
<script language="Javascript">
var whichone;
function writedata()
{
whichone = opener.thenumber
document.checkit.data.value = opener.thedata
}

function updateit()
{
if (whichone == 0)
{
opener.document.exampleform.data.value = document.checkit.data.value
}
else if (whichone == 1)
{
opener.document.exampleform.data1.value = document.checkit.data.value
}
window.close()
}
</script>
<body onload="writedata()">
<form name="checkit">
<textarea cols="50" rows="25" id="data">
</textarea><br />
<input type="button" value="Save Changes" onclick="updateit()">
</body>
</html>
The writedata() function runs once the page has loaded. First it gets the number held in the thenumber variable (so I know which textarea we are dealing with) and assigns it to the whichone variable. Then we use the thedata variable of the main page to write the contents (which is the appropriate textarea content) to the textarea in this pop up window.

The Save Changes button launces the updateit() function, which writes any changes made back to the appropriate textarea in the main page. Again an if, else if pair have been used to help us do this.

timcadieux
11-24-2002, 07:07 PM
This works quite well, and thanx! However, i am trying to get it to work with the RichText Editor, found at richtext.sourceforge.net. I cannot however, for the life of me get thier code example, which is terrible (but works) to work with your example (which is what i want).

my Example page looks like this..

<html>
<head>
<link rel="STYLESHEET" type="text/css" href="rte.css">


</head>

<body>
<input type="button" value="Edit" onClick="edit()">
<hr>
<div id="data" height="200">

<FORM name=exampleform>
<P><INPUT size=33 value=22 name=text> <INPUT type=button value=22 name=text> </P></FORM>
</div>
<script language="JavaScript">
function edit() {
var edit={}
edit.src = data.innerHTML;
edit.styledata=document.styleSheets
var ret;
ret = window.showModalDialog("popup_editor.html", edit,"dialogWidth:800px;dialogHeight:600px;help:no;status:no;scroll:no;resizable:yes;")
data.innerHTML = ret;
}
</script>
</body>
</html>

and my Popup looks like this..


<HTML>
<HEAD>
<META content="HTML 4.0" name="vs_targetSchema">
<META content="Microsoft Visual Studio 7.0" name="GENERATOR">
<title>Edit Text</title>
</HEAD>
<BODY leftMargin=0 topMargin=0>
<object id=richedit style="BACKGROUND-COLOR: buttonface" data="richedit.html" width="100%" height="100%" type="text/x-scriptlet" VIEWASTEXT>
</object>

<SCRIPT language="JavaScript">
var edit = window.dialogArguments;
</SCRIPT>

<SCRIPT language="JavaScript" event="onload" for="window">
window.returnValue = null;
if (edit.defaultFont) richedit.defaultFont = edit.defaultFont;
if (edit.defaultFontSize) richedit.defaultFontSize = edit.defaultFontSize;
if (edit.styledata) richedit.styledata = edit.styledata
richedit.docHtml = edit.src;
</script>
<SCRIPT language="JavaScript" event="onscriptletevent(name, eventData)" for="richedit">
//window.returnValue = eventData;
window.returnValue = richedit.docHtml;
window.close();
</script>

</BODY></HTML>


How can i add mulitple TextAreas to the Example page, and have the Popup retunr them to the correct spot? The above pages work great, however, due to my lack of undertsanding of JS, i have tried unsuccessfulyl to make the above pages work with multiple fileds, as per your example...both work, only, just on their own...

HELP!



Originally posted by MikeOS
Here is what I came up with, it may not be the best way as my javascript is a bit rusty, but it works. Here is the page that contains the textarea, I added another textarea to show how it works with more than one (although it is much easier with just one).

<html>
<body>
<head>
<script language="JavaScript">
var thedata;
var newwin;
var thenumber;
function edit(textarea)
{
if (textarea == 0)
{
thedata = document.exampleform.data.value
thenumber = 0

}
else if (textarea == 1)
{
thedata = document.exampleform.data1.value
thenumber = 1
}
newwin = window.open("popup_editor.html","","width=800,height=600,resizable")
}
</script>
</head>
<center>
<FORM name="exampleform">
<P> <textarea id="data" name="data" cols="50" rows="25"></textarea>
<input type="button" value="Edit" onclick="edit(0)"></P>
<P> <textarea id="data1" name="data1" cols="50" rows="25"></textarea>
<input type="button" value="Edit" onclick="edit(1)"></P>
</FORM>
</center>
</body>
</html>

You'll note three variables have been declared. thedata will get and store the data held in the appropriate textarea. newwin stores the new window object (the pop up window), thenumber tells me which textarea was clicked. You can see the edit() function in each call passes a number, this tells me which textarea was clicked, so I assign this number to the thenumber variable as I'll need it in the popup window. Note I used if, else if, instead of if, else as I thought you may be adding more textareas. Here is the popup window code:

<html>
<head>
<script language="Javascript">
var whichone;
function writedata()
{
whichone = opener.thenumber
document.checkit.data.value = opener.thedata
}

function updateit()
{
if (whichone == 0)
{

opener.document.exampleform.data.value = document.checkit.data.value
}
else if (whichone == 1)
{
opener.document.exampleform.data1.value = document.checkit.data.value
}
window.close()
}
</script>
<body onload="writedata()">
<form name="checkit">
<textarea cols="50" rows="25" id="data">
</textarea><br />
<input type="button" value="Save Changes" onclick="updateit()">
</body>
</html>
The writedata() function runs once the page has loaded. First it gets the number held in the thenumber variable (so I know which textarea we are dealing with) and assigns it to the whichone variable. Then we use the thedata variable of the main page to write the contents (which is the appropriate textarea content) to the textarea in this pop up window.

The Save Changes button launces the updateit() function, which writes any changes made back to the appropriate textarea in the main page. Again an if, else if pair have been used to help us do this.

msz
03-24-2006, 05:49 AM
Hi,

is it possible to do this with check boxes?

for example the main page has a text area. and instead of edit button it has get content. so pop up opens and brings a list of records from database. then the user can click check boxes of the records that he/she wants to paste to the text area at the main page and clicks submit so the pop up closes and sends the data back to the text area.

this could be to get a list of contacts from database and paste them into the text area, one per line so they cand send email to their contacts.