Javascript and GET method
Moderator: General Moderators
Javascript and GET method
How do I retrieve the values of vairables passed with the GET method on a form. I cant for the life of me remember
Passing Variables To Another Page
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.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.
Re: Javascript and GET method
You need to parse the query string, which can be accessed via the window.location.search and window.location.href objects.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
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) {
document.write('<P STYLE="padding-left: 24px">' + property + '</P>');
}
//-->
</SCRIPT>