Dynamic Form Items

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

    Dynamic Form Items

    Hello there I am trying to create A form that its fields will depend on a
    form menu.
    for example.
    /*************** *************** *************** **/
    <form name="form1" method="post" action="">
    <select name="select">
    <option value="1">optio n 1</option>
    <option value="2">optio n 2</option>
    <option value="3">optio n 3</option>
    </select>

    Text field 1<input type="text" name="textfield ">
    Text Field 2<input type="text" name="textfield 2">
    Text Field 3 <input type="text" name="textfield 3">
    Text Field 4 <input type="text" name="textfield 4">

    <input type="submit" name="Submit" value="Submit">
    </form>
    /*************** *************** *************** **/
    When the option 1 is selected only the textfields 1 and 2 to appear,
    when option 2 is selected only textfields 1 and 3 to appear and so on... any
    combination I would like.

    I tried puting the textfields in "if" statments but i don't like it. its too
    messy PHP and HTML code.
    Any Ideas of how this could be done better ? If someone did something
    similar before and has a relative link it would be good as well.

    Thanks
    Angelos!!


  • nice.guy.nige

    #2
    Re: Dynamic Form Items

    While the city slept, Angelos (angelos@redcat media.net) feverishly typed...
    [color=blue]
    > Hello there[/color]

    Hi
    [color=blue]
    > I am trying to create A form that its fields will depend
    > on a form menu.
    > for example.[/color]
    [...][color=blue]
    > When the option 1 is selected only the textfields 1 and 2 to appear,
    > when option 2 is selected only textfields 1 and 3 to appear and so
    > on... any combination I would like.[/color]

    I'm afraid I can't imagine how you are going to achieve this using PHP, as
    PHP does its work on the server, then delivers the page source to the user.
    You would be better looking for a client-side solution (eg. javascript) for
    this, such as the following list of options on Google:


    Just remember that not all users will have javascript turned on (or even
    available to them), so make sure that your form will still work without it.

    Hope that helps.

    Cheers,
    Nige

    --
    Nigel Moss http://www.nigenet.org.uk
    Mail address will bounce. nigel@DOG.nigen et.org.uk | Take the DOG. out!
    "Your mother ate my dog!", "Not all of him!"


    Comment

    • Angelos

      #3
      Re: Dynamic Form Items


      "nice.guy.n ige" <nigel_moss@dea dspam.com> wrote in message
      news:42821155$0 $371$cc9e4d1f@n ews.dial.pipex. com...[color=blue]
      > While the city slept, Angelos (angelos@redcat media.net) feverishly
      > typed...
      >[color=green]
      >> Hello there[/color]
      >
      > Hi
      >[color=green]
      >> I am trying to create A form that its fields will depend
      >> on a form menu.
      >> for example.[/color]
      > [...][color=green]
      >> When the option 1 is selected only the textfields 1 and 2 to appear,
      >> when option 2 is selected only textfields 1 and 3 to appear and so
      >> on... any combination I would like.[/color]
      >
      > I'm afraid I can't imagine how you are going to achieve this using PHP, as
      > PHP does its work on the server, then delivers the page source to the
      > user.
      > You would be better looking for a client-side solution (eg. javascript)
      > for
      > this, such as the following list of options on Google:
      > http://tinyurl.com/9oopm
      >
      > Just remember that not all users will have javascript turned on (or even
      > available to them), so make sure that your form will still work without
      > it.
      >
      > Hope that helps.
      >
      > Cheers,
      > Nige[/color]

      Thanks Nige I think you are right ... if I don't use javascript I am going
      to create seperate forms for each option...


      Comment

      • Kenneth Downs

        #4
        Re: Dynamic Form Items

        Angelos wrote:
        [color=blue]
        > Hello there I am trying to create A form that its fields will depend on a
        > form menu.
        > for example.
        > /*************** *************** *************** **/
        > <form name="form1" method="post" action="">
        > <select name="select">
        > <option value="1">optio n 1</option>
        > <option value="2">optio n 2</option>
        > <option value="3">optio n 3</option>
        > </select>
        >
        > Text field 1<input type="text" name="textfield ">
        > Text Field 2<input type="text" name="textfield 2">
        > Text Field 3 <input type="text" name="textfield 3">
        > Text Field 4 <input type="text" name="textfield 4">
        >
        > <input type="submit" name="Submit" value="Submit">
        > </form>
        > /*************** *************** *************** **/
        > When the option 1 is selected only the textfields 1 and 2 to appear,
        > when option 2 is selected only textfields 1 and 3 to appear and so on...
        > any combination I would like.
        >
        > I tried puting the textfields in "if" statments but i don't like it. its
        > too messy PHP and HTML code.
        > Any Ideas of how this could be done better ? If someone did something
        > similar before and has a relative link it would be good as well.
        >
        > Thanks
        > Angelos!![/color]

        A good way to avoid client-side processing is to do the old "wizard"
        approach. It has the advantage the users expect it and understand it.

        On page 1 they make a selection from the <select...> element. Off we go to
        the server, where you look at the option, save it in the session, and
        decide which fields to show on page 2. Or even easier, which page to go
        to.

        --
        Kenneth Downs
        Secure Data Software, Inc.
        (Ken)nneth@(Sec )ure(Dat)a(.com )

        Comment

        Working...