sending and recieving info. Please help!

They have: 5,633 posts

Joined: Jan 1970

I am trying to link to another page and send 1 piece of info with it. like this:
http://www.home.htm?var=hello

How can i access the variable var on the new page. Is there a way to do this in HTML or JAVA?

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

If you can use a Perl Script, you can get that variable using something like:

$index_string= $ENV{QUERY_STRING};

With JavaScript, I'll have to check, I can't remember if there is a way to it directly or if you have to split the document url. I'll get back if I find it.

<EDIT>
Aha, you can make it a js variable using the window.location.search property. This gets the variable and the ?, so you have to cut off the ?. I did it using the split method, but there may be an easier way:

function get_qs()
{
var qs=window.location.search;
var qs_arr=qs.split("?");
var your_var=qs_arr[1];
}

The variable your_var is the end result. It should be whatever is after the ?.

</EDIT>

[This message has been edited by John Pollock (edited 13 December 1999).]

They have: 5,633 posts

Joined: Jan 1970

I don't think you can pass variables with JavaScript. The command http://www.home.htm?var=hello looks just like an example of ASP.

John have you used your function get_qs() before? I can't really see what it is trying to do.

------------------
http://go.to/hass

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

You can't pass the variable, but if you click a link that uses the Query String, then the url for the next page will have the query string.

The function is just supposed to grab the string and make it a variable. I didn't add anything else. I tested it with an alert, and it works as long as the page is called with a query string, try it here (click the Go button when you get there):

http://www.pageresource.com/zzztest/testjp.htm?hello

Of course, the variable can't be stored, it could only be used as part of a javascript on that page.

I just read it in the NS docs, I was wondering about whether it would work as well.

[This message has been edited by John Pollock (edited 13 December 1999).]

[This message has been edited by John Pollock (edited 13 December 1999).]

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.