Javascript and GET method

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
toppac
Forum Commoner
Posts: 29
Joined: Fri Jun 14, 2002 10:44 am

Javascript and GET method

Post 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
honkyinc
Forum Newbie
Posts: 19
Joined: Tue Jun 04, 2002 10:30 am
Location: Maryland, USA

Post 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.
toppac
Forum Commoner
Posts: 29
Joined: Fri Jun 14, 2002 10:44 am

Post 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.
honkyinc
Forum Newbie
Posts: 19
Joined: Tue Jun 04, 2002 10:30 am
Location: Maryland, USA

Post 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)
Brian
Forum Contributor
Posts: 116
Joined: Thu Apr 18, 2002 5:33 pm

Passing Variables To Another Page

Post 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.
Brian
Forum Contributor
Posts: 116
Joined: Thu Apr 18, 2002 5:33 pm

Re: Javascript and GET method

Post 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>
Post Reply