Computer Help Community


Cyber Tech Help Community

New Tutorials

PC Tutorials

New Downloads

More Downloads
PC Downloads

Member Testimonials

Open Member Quote   Am grateful that I found this site. Receiveid prompt and helpful advice shortly after posting my first "insolvable problem". - Popster  Close Member Quote
Member Testimonials


Tech Help Community

Free Antivirus Scan

Free Virus Scan and a listing of the top 10 viruses in the wild - Free Antivirus Scan
Free Online Antivirus Scan

File Extension Database

Find what program a filetype belongs to in our searchable File Extension Database.
File Extension Database

Related Microsoft Links

Cyber Tech Help Community

To the top of the page to top


Tutorials | URL Parameter Passing in Javascript

Publish date: 19:02 Thursday, 28th July 2005
Written by: Steven Bentley
Audience intended for: Web Designers
Category: Web Design

Go up a levelGo up a level

You've probably seen sites which are programmed with a server-side language like PHP or a CGI script which use the URL to pass parameters around.

For example if you look at the URL of a Google search results page, it looks like this: - the bit after the q= is the query that I entered, in this case JavaScript, and I can change that to anything I like without having to go through their search box.

If you're working in JavaScript there are a couple of reasons why you might want to be able to do this, firstly if the pages of your site are being dynamically generated based on user input in a form then you can make a static link from another part of your site or from another site, for example if you're using a JavaScript search system you can link to the search results for a particular term. Another use is during development, often I make the "behind the scenes" stuff before I put the interface in, so it's handy for testing.

This week's tip lets you accept parameters from the URL using JavaScript



These two lines of code will return an array called urlterms which is derived from the URL, so if you went to



then you'd find that



You can also put text in, although any spaces you've left will come through as %20

You can have two copies of this code so that you can call two different functions from the URL.



will also work, although it's seems a little unreliable in Netscape. Just pass the stuff from the array in this case into a different function.

You can use



to check that there is a value after the ? or # if you find that you're getting undefined or JavaScript errors or any other unexpected results.


Please Note: if you have any questions about this tutorial please ask on our support forums
If you have written a tutorial of your own and would like to have it here on Cyber Tech Help all you have to do is Submit your tutorial and it will be reviewed by the Administrator.