Book Section
-----
TY JavaScript 3rd Ed.
Teach Yourself JS 1.5
Teach Yourself DHTML
Teach Yourself JS 1.3
LLWW: JavaScript

General Section
-----
Discussion Forum
Articles / Tips
JavaScript Links
About the Author
Privacy Policy
Contact Me



Other Sites
-----
Website Workshop
JavaScript Weblog

JavaScript Workshop Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
HINT: On Passing Data

 
Post new topic   Reply to topic    JSWorkshop Forum Index -> Articles
View previous topic :: View next topic  
Author Message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Wed Aug 28, 2002 9:07 am    Post subject: HINT: On Passing Data Reply with quote

To pass data between frames:

Assume in our frame set we have: Left, Center, Right frames.

Then in Center or Right we use: parent.Left.Var01 = 15; to change the value of Var01 in the Left frame.


To Pass data to/from a Pop-up window:

In the pop-up we use: window.opener.Var01 = 15; to change the value of Var01 in the original window.

In the original window we use: var NewWin = window.open(URL, "Child"); and then NewWinVar02 = 15.67; to change a value in the pop-up window.

WARNING The pop-up window MUST be open and ready for data before you issue the NewWin.Var02 = 15.67; line or no data will be passed!


Now, one last topic, to actually use or do something when a piece of data changes we could use a function like this in the <head> section:
Code:

  var Var01 = 0;
  var LastVal = Var01;
  function CheckUm() {
    if(Var01 != LastVal) {
      // Here we do whatever!
      alert("Var01 value has changed from "+LastVal+" to "+Var01);
      LastVal = Var01;
    }
    setTimeout("CheckUm();" 500); // check again in 1/2 sec.
  }
 
  .
  .
  .
 
  <body onLoad="CheckUm();">
  .
  .
  .
 


Now in any frame or window where we want to be able to do something when a given value changes we can.

Passing data between secondary related windows:

The only way I know to do this is via a cookie.

Frames and window.opener/child are directly related, a secondary relationship is a window opened from the same site but not by the initial window. All windows opened by the same site & location can access the same cookie. See my other article on Cookies:

http://jsworkshop.com/bb/viewtopic.php?t=15
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Thu Oct 17, 2002 6:27 am    Post subject: Reply with quote

Here's a link to my Test Website which has a Data Passing example:

http://cs.yrex.com/
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508


Last edited by phil karras on Mon Oct 31, 2011 7:06 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
anamika
New member
New member


Joined: 27 Mar 2003
Posts: 2

PostPosted: Fri Mar 28, 2003 5:22 am    Post subject: Reply with quote

thx,
was'nt exactly what I wanted, but got the idea. Was looking for a solution like window.showModalDialog(), but it does not works in netscape.

Can you suggest anything else.
Back to top
View user's profile Send private message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Fri Mar 28, 2003 12:44 pm    Post subject: Reply with quote

Not here, this is not the place for a specific question and answer only for article related information.

Ask your specific question on the JavaScript section of this site.
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
sohnee
Senior Member
Senior Member


Joined: 17 Jul 2002
Posts: 2054
Location: UK

PostPosted: Thu Apr 17, 2003 9:04 am    Post subject: Passing data to an iframe Reply with quote

You can also pass data to and from an <iframe>

Firstly, set up your iframes with a name:

Code:
<iframe src="about:blank" name="iframe1"></iframe>

<iframe src="about:blank" name="iframe2"></iframe>


In the main page you simply use the iframe name to call the function, variable or object you want. From an iframe, you can call functions variables and objects in the main page OR another iframe.

This is how you could do all of these things in one example...

save this as 'iframeexample.html'

Code:
<html>

<head>
<title>iframe example 1.0</title>
<script LANGUAGE="JavaScript" type="text/javascript">
var wot;

function anothertest(){
alert("This alert is from the parent.");
}

</script>
</head>

<body>
<p>Save this bit as 'iframeexample.html'</p>

<p><a href="#" onClick="iframe1.location.href='http://www.odford.co.uk';">Change the location of IFRAME 1</a></p>
<p><a href="#" onClick="iframe2.test();">Launch a function in IFRAME 2</a></p>

<p>
<iframe src="about:blank" name="iframe1" width="600" height="400"></iframe>
</p>

<p>
<iframe src="pagetwo.html" name="iframe2" width="400" height="200"></iframe>
</p>

</body>

</html>



save this as 'pagetwo.html'

Code:
<html>

<head>
<title>iframe example 1.0 - Page Two</title>
</head>

<body>
<p>Save this bit as 'pagetwo.html' in the same folder</p>

<p id="one"><a href="#" onClick="parent.iframe1.location.href='http://www.northernline.net';">Change the location of IFRAME 1 from IFRAME 2 via the 'parent' window.</a></p>
<p id="two"><a href="#" onClick="parent.anothertest();">Launch a function in 'Parent'</a></p>
<script LANGUAGE="JavaScript" type="text/javascript">
function test() {
alert('THIS ALERT HAS COME FROM IFRAME 2 - PAGE TWO');
}
</script>
</body>

</html>
Back to top
View user's profile Send private message Visit poster's website
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Tue May 13, 2003 8:00 am    Post subject: Basic function calling conventions: Reply with quote

Basic function calling convention, from the "top" frame:

If you put the function in the <head> section, then the form of an outside refernece is: parent.top.updateMe();. The correct form when the function is placed in an iframe (called: headerDiv) is: parent.top.frames.headerDiv.updateMe();

Reference: Unable to reference a function in another dhtml layer NS 7.0
http://jsworkshop.com/bb/viewtopic.php?t=855
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Wed Aug 06, 2003 11:01 am    Post subject: Passing Data from one page to another using <form> &am Reply with quote

There's is one more passing data topic that should be covered. It is passing data from a form on one page to another page. In this case the form posts the data, it gets placed in the URL and the new page looks at its URL and picks up the data. Once you have the data you can do whatever you want to it, place it into fields of a new form or whatever.

Here is the form in help266.htm:
Code:

<form name='test' post='help266.htm'>
  Enter your name: <input type='text' name='Name'>
  &nbsp; &nbsp;
  <input type='submit' name=='submit' value='submit'>
</form>


And here is one way to pick up the first FieldName, data pair in the second page:
Code:

   var data = new Array();
   var flds = new Array();

   // gets just sent data
   var tmp = document.location.search;

   // remove the ?
   data = tmp.split("?");

   // get all FieldName=data pairs
   data = data[1].split("&");

   // split first data pair into field & data
   flds = data[0].split("=");

   // display fieldName & data
   alert(flds[0] + "\n" + flds[1]);


I will be placing all this in help266.htm to show how it works and it will be up on my http://cs.yrex.com/ site.
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
karson
New member
New member


Joined: 16 Apr 2010
Posts: 1
Location: Pakistan

PostPosted: Fri Apr 16, 2010 7:38 am    Post subject: Solution pass values iframe to another iframe Reply with quote

1 Main.html // this is main page have in 2 iframes
2 leftframe.html // id is leftframe
3 rightframe.html // id is mainframe

==============================================
this code insert into "leftframe.html"
Add button and call hello function

<script language="javascript">
function hello()
{
top.frames["mainframe"].document.body.style.backgroundColor='red';
top.frames["mainframe"].document.getElementById("TITLE").value = 'HaAHAHAHAHAHAH';
}

</script>
=============================================

rightframe.html
please insert textbox the textbox id is "TITLE"
when you click on leftframe button then
right frame have change the value

I hope you have got my point its working very good
if you know about ajax you can play many script without
refresh page

Best Regards
Faisal Ismail A Karim
Pakistan
03332238826
Back to top
View user's profile Send private message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Tue Jul 13, 2010 6:50 am    Post subject: Reply with quote

Thanks Karson.

Yes, I know about Ajax and use it to do just that. However, these examples are all on the client side while Ajax is for posting/retrieving data to/from the server.
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    JSWorkshop Forum Index -> Articles All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
(c) 1997-2002 Starling Technologies and Michael Moncur. Portions (c) Sams Publishing.