tags:

views:

753

answers:

5

In PHP it is easy to pass parameter using $_GET[] and $_POST[]. Is there something like that in JavaScript? I hope I can pass parameter from address or form.

+1  A: 

You can use java script to set hidden form fields. When the form is posted the data will be transmitted to the server.

Ken
A: 

You have access to the query string from within javascript as well, so that should help.

Jonathan Arkell
A: 

What Ken said is the equivalent of POST variables. For passing values via GET you can append a querystring key to a link using javascript.

palmsey
+2  A: 

window.location.href contains the current page's URL. You can append your parameters to a page's URL after a "?" (i.e., a querystring), and have the javascript on that page parse them. Lots more information and examples on googlable pages like this one.

moonshadow
+1  A: 

If you're talking about passing parameters from one page to the next using purely client-side code, your best bet is probably to construct a normal URL query string, and append it on to the URL of the page you're navigating to when setting document.location.

On the target page, your client side code will have to parse document.location.href to get the individual URL parameters. Some Javascript libraries have helper functions to do this sort of parsing for you. Prototype, for example, can easily convert hash objects to and from URL query strings.

Joel Mueller