Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Problem! 1

Status
Not open for further replies.

Bignewbie

Programmer
Feb 22, 2001
351
PH
hey ppl! i need help.
how can i declare a variable on one page then get its value on a different page even when the page where it is declared already closed? i know this is possible 'coz i've seen it in a book somewhere! hope u guys can help me with this.


thanks and Godspeed!


biggie
 
Hi

you can declare a variable and pass it along the pages, or store in another page or even set a cookie. For example if you have a submit form, you can store the variable in a hidden field and then just keep on passing it. Or you can use Query String.

There are many ways to do this.

Hui Emagine Solutions, Inc.
 
no, no. i mean what code or how can i make variables persists pages?
 
Use a cookie. Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
You can use an object I created that will allow you to persist string and numerical values across pages. In the page that created it, make sure you tack it onto the url like so:

function moveOn()
{
self.location="newpage.htm?name="+somevalue
}

on newpage.htm, you can now acces the variable by including this object:

--------------------------
function QSHandler()
{
var i,j,tmparray,strata,prlen
strata = window.location.search
strata = strata.substring(1,strata.length)
if(strata.indexOf('&')>=0)
{
prsarray = strata.split('&')
prlen = prsarray.length
tmparray = new Array()
for(t=j=0;j<prlen;j++)
{
tmparray[t++] = prsarray[j].split('=')[0]
tmparray[t++] = prsarray[j].split('=')[1]
}
}
else
{
tmparray = new Array(strata.split('=')[0],strata.split('=')[1])
}
tlen = tmparray.length
this.data = new Array()
for(i=0;i<tlen;i++)
{
this.data[new String(tmparray)]=tmparray[++i]
}
this.QueryString=function(x)
{
return this.data[x]
}
}
Request = new QSHandler()

----------------------------------------
and calling:

thename = Request.QueryString(&quot;name&quot;)

now, thename holds the same value as somevalue from the last page
jared@eae.net -
 
jaredn,

looks complicated! but i'll give it a try. it seems you are using a query string to retrieve the variable... you are not implying a form now do u? and if udo, how come i dont need to submit it?


another clarification:
i ASP we have what's called as a Session variable which are the only variables able to be read and refered from one page to another without the need for a query string..... is there a javascript counterpart for this?

the only use of this question for me now is this: i have a secondary window which opens another window. what i need to do is to make the secondary window know that the window it opened has been closed. get my point? hope u do....

thanks


biggie
 
The primary window can notify the secondary window of its departure. Something like:

x=window.open(&quot;popuppage.htm&quot;)
self.onunload=function(){if(!x.closed){x.notifyClosed()}}

The QueryString object above was built to simulate its counterpart in server-side js (Request.QueryString). This technique will let you manually add items to the querystring, or use forms who's method is set to get. jared@eae.net -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top