PDA

View Full Version : passing variables to an iframe page



tvfoto
01-11-2007, 01:06 AM
Hi all,

THis may sounds classic to some experts out there but I cannot google out the right answer. Here we go again:

I have 1 main page(mainpage) and 2 iframes(ifram_left & iframe_right) within that main page. I have couple of checkbox and a drop downlist on the mainpage for navigation with a submit button (for ALL inputs selected) I dont know how to:
a) capture the values (collectively) from those inputs and pass them to either iframes.
b) pass variables from iframe_left to other inframe_right
c) on either iframe page, how to receive passing variables from mainpage and/or the other iframe page for processing.

Can some of you show me the way/links? Is cookie a better choice or??? Thanks in advance

VatsaL
01-14-2007, 02:27 AM
Not sure about iframes, but here s what you can do with frames:

http://javascript.internet.com/forms/pass-textbox-frames.html


hope it helps,

VatsaL

tvfoto
01-14-2007, 06:34 AM
I found how i can pass the variable from a main page (form) to an Iframe page (form1) but I have a dilema. ..How do I automatically capture the value of the textfield in (Iframe) page after it is populated by sending page.
How do I:
a) run the function Show() when the textfield in iframepage is populated by the parent page (mainpage)
b) how do parse/extract the passing value from the textfield (in iframepage).

Thanks

Here is my code for passing the variable.

mainpage.

<body>
<form name="form" method="post" action="">

<input type="text" name="textfield" />
<input type="button" name="button" name="button"
onclick="parent.frames['myIframe'].document.form1.textfield.value=
this.form.textfield.value"/>
</form>
<p>
<iframe name="myIframe" src="iframepage.htm"</p>
</body>


iframepage.

<script type="text/javascript">
{
var x=document.getElementById("form1").textfield.value
alert(x)
}
</script>
<body>
<form name="frame1" method="post">
<input type="text" name="textfield" onclick="show()"/>
<!-- onchange dont work here-->
</form>
</body>

Twey
01-14-2007, 07:59 PM
<script type="text/javascript">
var copying = false;

function copy(formName, fromName, frameName, frameFormName, toName) {
if(!copying) return;
var to = window.frames[frameName].document.forms[frameFormName].elements[toName],
from = document.forms[formName].elements[fromName];
to.value = from.value;
window.setTimeout(function() { copy(formNum, fromName, frameName, frameFormName, toName); }, 300);
}

function beginCopy(formName, fromName, frameName, frameFormName, toName) {
copying = true;
copy(formNum, fromName, frameName, frameFormName, toName);
}

function endCopy() {
copying = false;
}
</script>