Passing arguments to a script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hemanth

    Passing arguments to a script

    Hello,

    A novice question....

    I've a script that uses GET method and is called with two parameters
    (example.php?ar g1=val1&arg2=va l2). 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.ph p" 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"
    target="_parent ">
    <select>....</select> //option1
    <select>....</select> //option2
    <input type="submit" value="Display"/>
    </form>

    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)

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




    Appreciate your help.

    TIA
    Hemanth

  • ZeldorBlat

    #2
    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"/>
    </form>

    Comment

    • John Dunlop

      #3
      Re: Passing arguments to a script

      Hemanth wrote:
      [color=blue]
      > <form name="ex" method="GET" action="example .php?arg1=val1& arg2=val2"[/color]

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

      --
      Jock

      Comment

      • David Cartwright

        #4
        Re: Passing arguments to a script

        "Hemanth" <hemanth.singam setty@gmail.com > wrote in message
        news:1128650022 .222083.142550@ g49g2000cwa.goo glegroups.com.. .[color=blue]
        > I tried the following (hoping it would work;)
        > <form name="ex" method="GET" action="example .php?arg1=val1& arg2=val2"[/color]

        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!

        D.


        Comment

        • John Dunlop

          #5
          Re: Passing arguments to a script

          David Cartwright wrote:
          [color=blue]
          > [Hemanth wrote:]
          >[color=green]
          > > <form name="ex" method="GET" action="example .php?arg1=val1& arg2=val2"[/color][/color]

          [...]
          [color=blue]
          > it's a non-standard way of doing things,[/color]

          '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.

          --
          Jock

          Comment

          Working...