INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Sending data between pages

setting variable with query strings by GIGN
Posted: 17 Dec 00

We can send information to another page thru the use of a query string. It goes on the end of the URL when we give the href to a link:

 <a href="nextPage.htm?some variable=value>"
The ? sign indicates the start of the query string
we can have as many variable/value pairs as we like, we separate them using the & sign:

 ...?someVariable=value&someOther=value2...

When the next page is loaded the query string is stored for us at location.search .When it arrives the one above would look like this:

   ?someVariable=value&someOther=value2

which is one big string,
Note: If any spaces are left in the pairs, they come with %20 inserted instead.
  some variable --> some%20variable

 now we have to slice it up so we can use it. You can do many things, you could store them in a matrix, or just set the variables using eval (simpler).

function getQuery(){
   var queryString = location.search;
   
   -- get rid of ? at start --
   var data = queryString.slice(1,data_pre.length);
   
    
   -- Splits the string at the & and returns an array containing the parts, variable=value pairs.Stored as single string. --

   dataArray = data.split("&");         
       
   -- Here is where you could take each element of the dataArray and split at the = sign, and store the variable values separately. I am just going to set the variables. --
       
       for (j=0;j<dataArray.length;j++){
            eval(dataArray[j])
       }

}


So the first entry for our dataArray looked like:
         someVariable=value

 using eval(someVariable=value) sets the variable with it's value.

While sometimes these techniques are useful - a middleware solution is far les time consuming to set up. Server-Side pre-processors like ASP,PHP,PERL etc are ideally suited to this kind if job, and have pre defined methods making all of this unnecessary.

Back to Javascript FAQ Index
Back to Javascript Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close