Passing arguments to a script

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

A novice question....

I've a script that uses GET method and is called with two parameters
(example.php?arg1=val1&arg2=val2). This script outputs a html form with
two list boxes and a display button next to them.

Everytime I execute this form (i.e., select from listboxes and click on
the display button), I want call the same "example.php" script with the
selected listbox values (say, option1, option2) as well as the previous
arguments (va11, val2) - total 4 arguments.

I tried the following (hoping it would work;)
<form name="ex" method="GET" action="example.php?arg1=val1&arg2=val2"
<select>....</select> //option1
<select>....</select> //option2
<input type="submit" value="Display"/>

But when I click on the display, it calls example.php with only 2
values (option1, option2). My question is, is there a way to
- pass the first two arguments - val1,val2 (along with listbox values)

- store the val1, val2 as static variables so that they are available
everytime the script is called (without having to pass them as


Appreciate your help.


Re: Passing arguments to a script

Pass them as hidden parameters along with the form.  You'll find that
they show up in the URL on the next page:

<form name="ex" method="GET" action="example.php" target="_parent">
<select name="option1">....</select>
<select name="option2">....</select>
<input type="hidden" name="arg1" value="val1">
<input type="hidden" name="arg2" value="val2">
<input type="submit" value="Display"/>

Re: Passing arguments to a script

Hemanth wrote:

Quoted text here. Click to load it

some browsers before appending the form values strip the query part off
the action URL.


Re: Passing arguments to a script

Quoted text here. Click to load it

Someone else has mentioned that you should use <INPUT TYPE="hidden" ...>  
form elements. May I just add that the way you were hoping to do it is  
dangerous simply because it'll work on some systems and not others - oh, and  
because it's a non-standard way of doing things, it'll be a pain for anyone  
to debug in the future.

I say this because I've inherited some scripts that someone else wrote and  
which are done in exactly the way you describe, so it took me some  
head-scratching and "can you _really_ do it like that?" moments to figure  
out what was going on!


Re: Passing arguments to a script

David Cartwright wrote:

Quoted text here. Click to load it

Quoted text here. Click to load it

'non-standard' because as you say browsers handle it differently, it
deviates from the norm, and I suspect it's a case the spec writers
overlooked; but not because it doesn't comply with the spec - in this
sense it's not non-standard.


Site Timeline