Page 1 of 1

Javascript and GET method

Posted: Tue Jun 18, 2002 1:21 pm
by toppac
How do I retrieve the values of vairables passed with the GET method on a form. I cant for the life of me remember

Posted: Wed Jun 19, 2002 11:56 am
by honkyinc
As far as I'm aware, client-side JavaScript has no way to communicate between pages, unless those pages share a parent -> child relationship.

In other words, you can't pass variables to another page as you can with PHP.

Posted: Wed Jun 19, 2002 3:48 pm
by toppac
Yeah you're right. I had to do a work around, and pass the variables thru the URL then parse the URL to get the variables I wanted.

Posted: Wed Jun 26, 2002 1:48 pm
by honkyinc
Why reinvent the wheel? You could have just as easily used PHP to do the same thing with little to no effort. I understand if you were doing it just to see if it could be done though :o)

Passing Variables To Another Page

Posted: Sun Jul 07, 2002 2:27 am
by Brian
honkyinc wrote:As far as I'm aware, client-side JavaScript has no way to communicate between pages, unless those pages share a parent -> child relationship.

In other words, you can't pass variables to another page as you can with PHP.
Sure you can. JavaScript does not set variables automatically based upon GET data as PHP does, but it is able to access the query string for the current page via window.location.search and windows.location.href.

Re: Javascript and GET method

Posted: Sun Jul 07, 2002 2:32 am
by Brian
toppac wrote:How do I retrieve the values of vairables passed with the GET method on a form. I cant for the life of me remember
You need to parse the query string, which can be accessed via the window.location.search and window.location.href objects.

Just paste this into an HTML page to play around with window.location properties:

Code: Select all

<SCRIPT TYPE="text/javascript">
<!--

// Properties of the "window.location" Object
// Brian Sexton

// Friday, July 6th, 2002 -- Just Before Midnight

// This is for a response to an inquiry posted at the following URL:
// http://www.devnetwork.net/forums/viewtopic.php?t=964


document.write('<P STYLE="font-weight: bold">Here are two sample properties of the "window.location" object and their current values:</P>');

document.write('<P STYLE="padding-left: 24px"><SPAN STYLE="font-weight: bold">window.location.href:</SPAN> ' + window.location.href + '</P>');

document.write('<P STYLE="padding-left: 24px"><SPAN STYLE="font-weight: bold">window.location.search:</SPAN> ' + window.location.search + '</P>');


document.write('<BR>');


document.write('<P STYLE="font-weight: bold">Here are all the properties of the "window.location" object:</P>');

for (property in window.location) &#123;

  document.write('<P STYLE="padding-left: 24px">' + property + '</P>');

&#125;

//-->
</SCRIPT>