View Full Version : Help sending objects from one page to another.
jhd121
08-28-2002, 06:07 AM
I am fairly new to Javascript and I am looking for a way to send a variable from one page to another using the www.blah.com?variable=something format. How can I then access the variable to use in my next page. I tried using the tutorial on this but didn't quite understand. Maybe someone could spell it out a little better. Thank you!
Joel
glenngv
08-28-2002, 06:21 AM
location.search returns the querystring beginning with ?
in your example, it would return ?variable=something
from there, you can parse it to get the value of each parameter (if you have many)
if you have only 1 paramater, i suggest you use only www.blah.com?something so that it's easier to parse
jhd121
08-28-2002, 02:21 PM
So do I just say:
x = location.search
to have x have the value of "?something" ?
A1ien51
08-28-2002, 05:25 PM
For the simpliest solution, look here
http://www10.brinkster.com/A1ien51/scripts/Sendit.htm?HelloThere
jhd121
08-28-2002, 07:29 PM
That worked great. Thank you very much. If you had a little time would you mind explaining what the line:
document.location.href.slice(PageAddy.length+1,document.location.href.length)
does exactly. That is the part I am unfamiliar with.
Thank you
joh6nn
08-29-2002, 12:46 AM
x = location.search
x has the value of "?something"
that's exactly right. this:
document.location.href.slice(PageAddy.length+1,document.location.href.length)
is another way of achieving the same effect. document.location is the url object. it should actually be window.location. document.location is a bug, that works, but the correct form is window.location. the href property of the location object, means the entire url, so everything, including the search string. PageAddy is the length of the url, up to the search string; the plus-one, means everything up to the ? then, there's the entire length of the url, again. the slice() part, means cut out this, and give it back to me. so cut out everything starting after the ?, and going to the end of the whole url, which would be the variable that you passed.
this could be more easily accomplished with the following:
var passedVar = window.location.search.slice(1);
this takes the search property of the location object ( the ?, and everything after it ), and cuts it, starting after the ? ( character position 0 would be the ?, so character position 1 is right after the ? ) and going to the end of the string ( the slice() method takes two arguments: start position, inclusive; end position, exclusive. if you leave out the second argument, string.length is the default ).
hope that explains things for you.
jhd121
08-29-2002, 01:42 AM
That's awesome! Thanks a lot.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.