PDA

View Full Version : How dou you write from frame to frame?


Kinky
10-12-2002, 06:39 AM
Here's the scenario:
My web page is supposed to simulate a buying site
At the top are text boxes that are used to scroll thru an array.
Under that is another textbox and a button. When pressed, the button searches thru the array for a match and chages the top text boxes to show this. Another button is supposed to take the information displayed in the top text boxes and send them into a textarea, a la shopping basket.
WHat code is needed for the last button, give or take?
I would also like the code to be as simple as possible, as i am only a beginner

Mr J
10-12-2002, 01:35 PM
If you are going to actually right to another page then use

document.write()

loaded into the frame that you want

adios
10-12-2002, 05:50 PM
Wherever it is, you output to a <textarea name="TA"> like so:

document.form_name.TA.value = 'string';

Prepended (in front of that) could be anything - or nothing, if the textarea is in the same window (frame) as the script is running. I'll guess from your topic we're writing cross-frame here.

<script type="text/javascript" language="javascript">

function addToCart(f) {
var str = '', getFields = new Array('textbox1','textbox2','textbox3'); //names of boxes to transfer
for (var i=0; i<getFields.length; ++i)
if (f[getFields[i]].value) str += f[getFields[i]].value + '\n';
top.otherframe.document.myform.mytextarea.value = str;
}

</script>
<input type="button" value="Add to Cart" onclick="addToCart(this.form)">

This is for a <frame name="otherframe"> with a <form name="myform"> and - d'oh - <textarea name="mytextarea">. I kicked in a line feed (\n) between the entries, but, naturally, you can format it any way you'd like.