problem with <select multiple="true">

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

    problem with <select multiple="true">

    Hi,

    I have a form with a select element with multiple="true" . When using the
    GET method (I suppose the same happens with the POST method) I can seen
    that the form sends channels=CH1&ch annels=CH2 when CH1 and CH2 have been
    choosen. $_GET["channels"] gives me "CH2". Is there any way to get all
    the choosen channels elements? I would be very appreciative for any
    help. Thank you in anticipation.

    Regards

    Rolf Wester

    ----------------

    part of the form element:

    echo "<select size=5 name=\"channels \" multiple=\"true \">";
    echo "<option> CH1 </option>";
    echo "<option> CH2 </option>";
    echo "<option> CH3 </option>";
    echo "<option> CH4 </option>";
    echo "<option> CH5 </option>";
    echo "</select>";

  • Alvaro G Vicario

    #2
    Re: problem with &lt;select multiple=&quot; true&quot;&gt;

    *** Rolf Wester wrote/escribió (Wed, 21 Jan 2004 12:42:03 +0100):[color=blue]
    > I have a form with a select element with multiple="true" . When using the
    > GET method (I suppose the same happens with the POST method) I can seen
    > that the form sends channels=CH1&ch annels=CH2 when CH1 and CH2 have been
    > choosen. $_GET["channels"] gives me "CH2". Is there any way to get all
    > the choosen channels elements?[/color]

    The easiest way is to make channels become an array:

    <select name="channels[]"></select>


    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --

    Comment

    • Jon Kraft

      #3
      Re: problem with &lt;select multiple=&quot; true&quot;&gt;

      Rolf Wester <wester@ilt.fra unhofer.de> wrote:
      [color=blue]
      > I have a form with a select element with multiple="true" . When using the
      > GET method (I suppose the same happens with the POST method) I can seen
      > that the form sends channels=CH1&ch annels=CH2 when CH1 and CH2 have been
      > choosen. $_GET["channels"] gives me "CH2". Is there any way to get all
      > the choosen channels elements? I would be very appreciative for any
      > help. Thank you in anticipation.
      >
      > Regards
      >
      > Rolf Wester
      >
      > ----------------
      >
      > part of the form element:
      >
      > echo "<select size=5 name=\"channels \" multiple=\"true \">";[/color]

      echo "<select size=5 name=\"channels[]\" multiple=\"true \">";

      Makes $channels an array.

      HTH;
      JOn

      Comment

      • John Dunlop

        #4
        Re: problem with &lt;select multiple=&quot; true&quot;&gt;

        Rolf Wester wrote:
        [color=blue]
        > I have a form with a select element with multiple="true" . When using the
        > GET method (I suppose the same happens with the POST method) I can seen
        > that the form sends channels=CH1&ch annels=CH2 when CH1 and CH2 have been
        > choosen. $_GET["channels"] gives me "CH2". Is there any way to get all
        > the choosen channels elements?[/color]

        You've been shown the solution, viz., change your select element's
        name to end in "[]". This is actually a FAQ.



        In HTML, the multiple attribute doesn't take the value "true", nor
        does it take the value "yes", as PHP.net's FAQ creator would have you
        misbelieve. If any of those values are used, it's only by dint of
        browsers' error-recovery that users are able to select multiple
        options at all. The multiple attribute either takes the value
        "multiple", or it can exist in minimised form: only the attribute
        value "multiple" is left, i.e.,

        <select multiple>

        The latter is preferred, according to HTML4.01, sec. B.3.4.

        --
        Jock

        Comment

        • Rolf Wester

          #5
          Re: problem with &lt;select multiple=&quot; true&quot;&gt;

          Rolf Wester wrote:[color=blue]
          > Hi,
          >
          > I have a form with a select element with multiple="true" . When using the
          > GET method (I suppose the same happens with the POST method) I can seen
          > that the form sends channels=CH1&ch annels=CH2 when CH1 and CH2 have been
          > choosen. $_GET["channels"] gives me "CH2". Is there any way to get all
          > the choosen channels elements? I would be very appreciative for any
          > help. Thank you in anticipation.
          >
          > Regards
          >
          > Rolf Wester
          >
          > ----------------
          >
          > part of the form element:
          >
          > echo "<select size=5 name=\"channels \" multiple=\"true \">";
          > echo "<option> CH1 </option>";
          > echo "<option> CH2 </option>";
          > echo "<option> CH3 </option>";
          > echo "<option> CH4 </option>";
          > echo "<option> CH5 </option>";
          > echo "</select>";
          >[/color]
          Thank you all very much for the help.

          Rolf Wester

          Comment

          • Agelmar

            #6
            Re: problem with &lt;select multiple=&quot; true&quot;&gt;

            John Dunlop wrote:[color=blue]
            > Rolf Wester wrote:
            >[color=green]
            >> I have a form with a select element with multiple="true" . When using
            >> the GET method (I suppose the same happens with the POST method) I
            >> can seen that the form sends channels=CH1&ch annels=CH2 when CH1 and
            >> CH2 have been choosen. $_GET["channels"] gives me "CH2". Is there
            >> any way to get all the choosen channels elements?[/color]
            >
            > You've been shown the solution, viz., change your select element's
            > name to end in "[]". This is actually a FAQ.
            >
            > http://www.php.net/manual/en/faq.htm...elect-multiple
            >
            > In HTML, the multiple attribute doesn't take the value "true", nor
            > does it take the value "yes", as PHP.net's FAQ creator would have you
            > misbelieve. If any of those values are used, it's only by dint of
            > browsers' error-recovery that users are able to select multiple
            > options at all. The multiple attribute either takes the value
            > "multiple", or it can exist in minimised form: only the attribute
            > value "multiple" is left, i.e.,
            >
            > <select multiple>
            >
            > The latter is preferred, according to HTML4.01, sec. B.3.4.[/color]

            Actually, the former is preferred (<select multiple="multi ple"...>)
            Attribute minimization is actually forbidden in XHTML, which is the
            preferred standard. And just FYI, what you're quoting (the HTML 4.01
            Specification) was developed in from 1997-1999 and finally approved in 1999.
            This was written when Netscape 4.x was still the primary browser to develop
            for. Now, we consider anyone using Netscape 4.x to be a hopeless cause. All
            browsers today* (all meaning >99%) support the non-minimized form.

            See: http://www.w3.org/TR/xhtml1/#diffs

            *Data taken from the W3C, showing that in July 03, 59% were using IE6, 34%
            using IE5, 1% using IE4 (all of which supported the non-minimized form) and
            only 1% using Netscape 4x. These numbers have likely changed greatly in the
            past five months, with the rise of Mozilla and Firebird, and of course the
            ever increasing popularity of IE6... I would put the number of users of
            Netscape 4.x at well below 1% today. See:
            W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.



            Comment

            • John Dunlop

              #7
              Re: problem with &lt;select multiple=&quot; true&quot;&gt;

              Agelmar wrote:
              [color=blue]
              > [...] XHTML, which is the preferred standard.[/color]

              Preferred by whom? Impetuous duhzyners? It's gotta be the X, it sends
              them crazy! HTML just lacks that certain X-factor, doesn't it?

              :-]



              (BTW, XHTML1.0 isn't a standard; the W3C isn't -- and can't be -- a
              standards body, the far-reaching misconception notwithstanding .)
              [color=blue]
              > [The HTML4.01 specification] was written when Netscape 4.x was still
              > the primary browser to develop for.[/color]

              Ah, are we talking at cross-purposes here? My comments concern
              authoring for the WWW, not severely restricted intranets.

              --
              Jock

              Comment

              Working...