Re: [HELP] Javascript - reading values from URLs

by "rudy" <r937(at)interlog.com>

 Date:  Mon, 18 Dec 2000 00:25:47 -0500
 To:  "Jose Casal-Gimenez" <J.Casal(at)ukc.ac.uk>,
"HWG Techniques" <hwg-techniques(at)hwg.org>
  todo: View Thread, Original
>.http://domain/folder/index.html?variable=3
>
>How can I get to read the "variable" using Javascript?


hi jose

location.search is the stuff after the question mark (it was defined that
way so you wouldn't have to look for the question mark yourself)

so if "variable" (8 characters long) is the name of your, um, variable,
then you can grab the value like this:

   varvalue = document.location.search.substring(10)

the substring starts after the equal sign and goes to the end of the string
this method won't work if somebody types the url and makes a mistake when
typing "variable," but if the url is passed by a GET from a form that you
designed, then this will work

simple, yet effective    ;o)

rudy.ca

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA