Variable passing

This is a discussion on "Variable passing" within the JavaScript Forum section. This forum, and the thread "Variable passing are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Oct 5th, 2006, 07:03
Junior Member
Join Date: Dec 2005
Location: Netherlands
Age: 46
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Question Variable passing

Hi,
I'm looking for an easy way to take a variable (i.e. myPageNumber) to another page. When I click on a link to the other page, I want the new page to 'remember' from which page a came. For some reason I don't want to use <history> or <cookies>. I read somewhere that this can be done via the url, but I'not sure how this exacty works, and how I can extract the variabe from the url (into the new page).
Can anyone help me out here with a simple example what to do on both (sending and receiving) pages?

Thankx, Hans
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Oct 5th, 2006, 10:39
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

Yes this can be done. I haven't got time to explain it now but will get back to you later.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 5th, 2006, 15:13
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

Ok. Before we look at a solution, what information do you want to pass from page to page and why?

I ask you this in case the information could be sensitive in any way, in which case you would not want it appearing in the address bar of the browser.

You also need to think about the fact that if this information was of a sort that could be hard-coded into the links, ongoing maintainance could quickly become a real pain.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Oct 29th, 2006, 06:38
Junior Member
Join Date: Dec 2005
Location: Netherlands
Age: 46
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Re: Variable passing

Quote:
Originally Posted by ukgeoff View Post
Ok. Before we look at a solution, what information do you want to pass from page to page and why?

I ask you this in case the information could be sensitive in any way, in which case you would not want it appearing in the address bar of the browser.

You also need to think about the fact that if this information was of a sort that could be hard-coded into the links, ongoing maintainance could quickly become a real pain.
Hi ukgeoff, sorry for not responding earlier, be I've been quite buzy lately..

What I have is:

a number of pages with a kind of storyline within time:
let's name it storypage#1, storypage#2 ...... storypage#X

a number of pages with a kind of subjectline' with certain subjects:
let's name it subjectpage#1 .... subjectpage#X

Another section contains the real info:
let's name it infopage#1....infopage#x

The infopages can be entered from both the storypages and subjectpages.

What I would like to remember is when I enter an infopage from either the storyline pages or the subjectpages, is the storypage- or subjectpage number or variable, so that I can continue with my story or subject after reading the info.

To make it more complicated: Sometimes I need to view more infopages before returning to either the original storypage or original subjectpage, so I figure that {javascript: history.back} won't help me, unless I can count the number of histories between entering and leaving the infopages.


I hope I made myself clear, and I really appreciate your help.
Regards Hans
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Oct 29th, 2006, 14:35
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

Ok, there are some limitations / problems with what you want to do.

You are assuming that the user is going to want to navigate the same way you would have. This second guessing could lead to the user becoming irritated and leaving the site altogether.

You are effectively creating your own history chain which you will need to manage and pass from page to page.

What happens if the user decide to use their back / forward button instead?

Is this really viable?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Oct 29th, 2006, 15:58
Junior Member
Join Date: Dec 2005
Location: Netherlands
Age: 46
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

They need to click more 'backs' to return to the storyline instead of the link 'go back to the storyline' I would like to create. In fact it's even more complicated, because I use frames, and in some cases 3 frames change by leaving the storypath to the info-items, but it might be 2 frames in some cases.

So my thought was: if I remember were I came from by 'knowing' a number generated by the page I origianally came from, it looks easy to me to use a link 'go back' no matter where I came from, telling javascript if variable a = 1, b=4, c=8: go back to storyline page a, frame2 (buttons) page b (=4), frame 3 (topframe, naviagation) page c (=8) etc.

I guess if the user is really interested in the storyline with the addition of extra info, the navigation I would like to provide is the easiest way....but I would like to find out myself if that's the case :-)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Oct 29th, 2006, 20:35
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

Frames are the devils play thing and should be banned but in this case they are the solution to what you want to do.

Set up a frame who's dimensions are such that the frame is not seen. Because that frame never changes, you can then set up a JavaScript variable in that frame which becomes your memory store.

Set up an array which you operate as a last-in first-out stack.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Oct 30th, 2006, 14:16
Junior Member
Join Date: Dec 2005
Location: Netherlands
Age: 46
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Re: Variable passing

Quote:
Originally Posted by ukgeoff View Post
Frames are the devils play thing and should be banned but in this case they are the solution to what you want to do.



Set up a frame who's dimensions are such that the frame is not seen. Because that frame never changes, you can then set up a JavaScript variable in that frame which becomes your memory store.

Set up an array which you operate as a last-in first-out stack.
How ?

I'm not a javascript guru, which means I only use it for preloading images and simple functions as multiloads or simple tasks. That's why I needed some help in the first place.......

Regards Hans
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Oct 30th, 2006, 14:45
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

You have obviously created quite a complex frame structure. Usually the frame structure doesn't change from page to page, just the elements that are in the various frames.

Can you not select a frame that is always there and place the necessary JavaScript in that?

Alternative add another frame that will always be there.

What are you using to produce your pages and frame structure?

Do you know how to call functions in one frame from within another frame?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Oct 31st, 2006, 05:36
Junior Member
Join Date: Dec 2005
Location: Netherlands
Age: 46
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow Re: Variable passing

Quote:
Originally Posted by ukgeoff View Post
You have obviously created quite a complex frame structure. Usually the frame structure doesn't change from page to page, just the elements that are in the various frames.

Can you not select a frame that is always there and place the necessary JavaScript in that?

Alternative add another frame that will always be there.

What are you using to produce your pages and frame structure?

Do you know how to call functions in one frame from within another frame?
Hi Geoff, maybe you can have a peek at my site http://www.mandalapagina.org/1024index.htm so it's easier for me to explain. (It's in dutch, but I'll translate,if necessary).
This side is meant to be for multiple purpose: 1) A review for drawing and painting materials; 2) My personal story of my drawings; 3) overview of drawings without the story.

When you enter the site, in the left frame you'll find the main menu, in the top frame navigation and (if available) submenu's, in the right frame the explanation of the topic. (Not every button is working yet).
By clicking on TEKEN- EN SCHILDERMATERIALEN (drawing and painting materials) you'll see buttons appear in the top frame, related to this topic.
Choose KLEURPOTLODEN (colourpencils);WATERVASTE KLEURPOTLODEN;option 5: Prismacolor Premier. You'll see that the top and right frame changes with every click. On this level the topic TEKEN- EN SCHILDERMATERIALEN will meet the storyline..... The (not yet a) link 'mandala's' should bring you back to.....

By clicking DE REIS NAAR BINNEN (journey inside) - maart 2006 (march), please click on the thumbnail on this page, you'll find a short overview of this drawing. From here you'll get the option to travel further, see with which materials this drawing was made, or see other drawings. By clicking the link 'kleurpotloden' (not yet a link) will bring you to the info as explained earlier, but NOW I want to remember that I came from this page, so when I click 'mandala's' in the TEKEN- EN SCHILDERMATERIALEN section, I will come back here.

I hope you'll see my point in choosing something like 'passing variables' to remember where I came from, because more drawings are made by the same drawing-materials.

Regards Hans
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Oct 31st, 2006, 14:21
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

Had a look at you site and the code behind it.

What I'm thinking at the moment is that you could maintain an array as a variable as mentioned previously. Then when you call your function - multiload3, that array could be appended to one of the file calls, for example;
Code: Select all
parent.topFrame.location.href=doc1?myarray;
Then you could have an onload event that extracted that variable from the refering url so that it is available for further manipulation.

You could in theory maintain an array for each of the three frames.

Am I making sense?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Oct 31st, 2006, 14:32
Junior Member
Join Date: Dec 2005
Location: Netherlands
Age: 46
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

Hi Geoff,

Thanks for the effort to look into the problem. Right now I have no clue what you mean, but I will have a look it it and try if I can make chocolat of it [ dutch expression :-) ]. If not, I will let you know later on.

Thanx, Hans
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Nov 1st, 2006, 08:24
Junior Member
Join Date: Dec 2005
Location: Netherlands
Age: 46
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

Quote:
Had a look at you site and the code behind it.

What I'm thinking at the moment is that you could maintain an array as a variable as mentioned previously. Then when you call your function - multiload3, that array could be appended to one of the file calls, for example;


Code: Select all
parent.topFrame.location.href=doc1?myarray;

Then you could have an onload event that extracted that variable from the refering url so that it is available for further manipulation.

You could in theory maintain an array for each of the three frames.

Am I making sense?
Hi Geoff,
I have had a look into this code and I found some examples which work for a single reference. Now I'm struggeling with how to use it in a <javacript:Multiload3>function.

What I've done so far:
Code: Select all
<SCRIPT LANGUAGE="JavaScript">
<!-- Hiding
// Reference of leaving page
var data = new Array();
data[0] = "tf, ../1024mandalas/1024M0001T.htm";
data[1] = "lf, ../1024mandalas/1024MandalaL.htm";
data[2] = "rf, ../1024mandalas/1024M0001.htm";
function sendData()
{
  // Initialize packed or we get the word 'undefined'
  var packed = "";
  for (i = 0; (i < data.length); i++) {
    if (i > 0) {
      packed += ",";
    }
    packed += escape(data[i]);
  }
 //location to send data to
  parent.mainFrame.location.href="../1024papier/1024WPCR.htm?" + packed;
}</script>
calling
HTML: Select all
<a href="javascript:sendData()">papier</a>
on the sending page and

Code: Select all
<SCRIPT LANGUAGE="JavaScript">
<!-- Hiding
  var query = window.location.search;
  // Skip the leading ?, which should always be there, 
  // but be careful anyway
  if (query.substring(0, 1) == '?') {
    query = query.substring(1);
  }
  var data = query.split(','); 
  for (i = 0; (i < data.length); i++) {
    data[i] = unescape(data[i]);
  }</script>
on the receiving page, which works fine. But I want to combine this <sendData> funtion into the
Code: Select all
function multiLoad3(doc1,doc2,doc3) {
  parent.topFrame.location.href=doc1;
  parent.mainFrame.location.href=doc2;
  parent.leftFrame.location.href=doc3;
}
the data should only be sent to doc2.

Can you please give me a clue ?

Thanks,
Hans
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Nov 1st, 2006, 12:18
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

Is there some reason why you can't call sendData() as the first line of code in your multiLoad3() function?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Nov 1st, 2006, 13:30
Junior Member
Join Date: Dec 2005
Location: Netherlands
Age: 46
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

Quote:
Is there some reason why you can't call sendData() as the first line of code in your multiLoad3() function?
I can put a sendData() as the first line in the multiload3:
Code: Select all
function multiLoad3(doc1,doc2,doc3) {
sendData()
parent.topFrame.location.href=doc1;
parent.mainFrame.location.href=doc2;
parent.leftFrame.location.href=doc3;
}
but I don't know where to place the reference which points to the page in which the data should be received.
Code: Select all
function sendData()
{
// Initialize packed or we get the word 'undefined'
var packed = "";
for (i = 0; (i < data.length); i++) {
if (i > 0) {
packed += ",";
}
packed += escape(data[i]);
}
//location to send data to
parent.mainFrame.location.href="../1024papier/1024WPCR.htm?" + packed;
}
The html link calling the multiLoad3-function
HTML: Select all
<a href="javascript:multiLoad3('../1024papier/1024WPCT.htm', '../1024papier/1024WPCR.htm', '../1024TekenL.htm')">papier</a>
results in this this case in only changing doc1, probably because
parent.mainFrame.location.href is called in both functions with different arguments.

I have no clue how to tell multiLoad3 to add the argument "?" + packed behind doc2, because that should do the trick (or not ?)

Regards Hans
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Nov 1st, 2006, 14:04
Junior Member
Join Date: Dec 2005
Location: Netherlands
Age: 46
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

Hi Geoff,

I already found out,
I need to remove the second line from the multiLoad3 - function, and then it works perfectly.

Thanx for pointing me in the right direction !
Regards Hans
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Nov 1st, 2006, 21:15
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

I hope the chocolate tastes good ;-)

I'm a plain chocolate fan myself.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #18  
Old Nov 2nd, 2006, 14:25
Junior Member
Join Date: Dec 2005
Location: Netherlands
Age: 46
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Variable passing

Quote:
I hope the chocolate tastes good ;-)

I'm a plain chocolate fan myself.
Hi Geoff, yes it did.....

But now I run into new challenges. I should probably open a new thread...

What I want to know now:

Is it possible to load a certain image into a table-cell depending on a certain variable-value which I have sent from one page to the other?

e.g. value = 1 -> send value to second page and open here picture 1.

and if so can this also be done with with a <a href=...></a> ?

if the value > 0 a reference with a multiload-function containing data[1],data[2] and data[3] is added to the picture, (referring to my top,left en mainFrame of the leaving page), and if the value = 0 no reference should be added.

Thanks,
Regards Hans
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #19