Return multiple value from an option item

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

    #1

    Return multiple value from an option item

    Hi,

    I've a problem, I've a select tag with n items. It is build from a db
    request with an id, a code and a label. I need to get the id and the
    code when the user select a label. How can I do that without doing an
    other request to database ? Can I use array as value attribute of option
    tag ?

    Thanks

    Fred
  • Jarmo

    #2
    Re: Return multiple value from an option item

    "Frederic" <fh@ionicsoftDO Tcom> wrote in message
    news:421b0a56$0 $2021$6c56d894@ feed0.news.be.e asynet.net...[color=blue]
    > Hi,
    >
    > I've a problem, I've a select tag with n items. It is build from a db
    > request with an id, a code and a label. I need to get the id and the
    > code when the user select a label. How can I do that without doing an
    > other request to database ? Can I use array as value attribute of option
    > tag ?
    >
    > Thanks
    >
    > Fred[/color]

    Why don't you make the value equal to the id plus the code? Using a safe
    delimiter that's in neither field, for example.

    <option value="myid::my code">myname

    The you can parse the value in JavaScript as necessary, splitting on the
    delimiter ("::" in the example).


    Comment

    • RobB

      #3
      Re: Return multiple value from an option item

      Jarmo wrote:[color=blue]
      > "Frederic" <fh@ionicsoftDO Tcom> wrote in message
      > news:421b0a56$0 $2021$6c56d894@ feed0.news.be.e asynet.net...[color=green]
      > > Hi,
      > >
      > > I've a problem, I've a select tag with n items. It is build from a[/color][/color]
      db[color=blue][color=green]
      > > request with an id, a code and a label. I need to get the id and[/color][/color]
      the[color=blue][color=green]
      > > code when the user select a label.[/color][/color]

      Assume you meant 'selects an option'.
      [color=blue][color=green]
      > > How can I do that without doing an
      > > other request to database ? Can I use array as value attribute of[/color][/color]
      option[color=blue][color=green]
      > > tag ?
      > >
      > > Thanks
      > >
      > > Fred[/color]
      >
      > Why don't you make the value equal to the id plus the code? Using a[/color]
      safe[color=blue]
      > delimiter that's in neither field, for example.
      >
      > <option value="myid::my code">myname
      >
      > The you can parse the value in JavaScript as necessary, splitting on[/color]
      the[color=blue]
      > delimiter ("::" in the example).[/color]

      Don't use form fields to store data: javascript provides data storage
      for programming.

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
      <html>
      <head>
      <title>untitled </title>
      <script type="text/javascript">

      //echo these from the dB

      var ids =
      {
      alpha: 'alphaID' ,
      beta: 'betaID' ,
      gamma: 'gammaID' ,
      delta: 'deltaID' ,
      epsilon: 'epsilonID'
      };

      var codes =
      {
      alpha: 'alphaCODE' ,
      beta: 'betaCODE' ,
      gamma: 'gammaCODE' ,
      delta: 'deltaCODE' ,
      epsilon: 'epsilonCODE'
      };

      function display(obj)
      {
      var v = obj.options[obj.selectedInd ex].value;
      alert(
      'ID: ' + ids[v] +
      '\n\n' +
      'CODE: ' + codes[v]
      );
      }

      </script>
      </head>
      <body>
      <form>
      <select onchange="if(va lue)display(thi s)">
      <option value="">- pick -</option>
      <option value="alpha">a lpha</option>
      <option value="beta">be ta</option>
      <option value="gamma">g amma</option>
      <option value="delta">d elta</option>
      <option value="epsilon" >epsilon</option>
      </select>
      </form>
      </body>
      </html>

      Comment

      • Jarmo

        #4
        Re: Return multiple value from an option item

        "RobB" <ferndoc9@hotma il.com> wrote in message
        news:1109096638 .581986.24700@g 14g2000cwa.goog legroups.com...[color=blue]
        > Jarmo wrote:[color=green]
        > > "Frederic" <fh@ionicsoftDO Tcom> wrote in message
        > > news:421b0a56$0 $2021$6c56d894@ feed0.news.be.e asynet.net...
        > >
        > >
        > > <option value="myid::my code">myname
        > >
        > > The you can parse the value in JavaScript as necessary, splitting on
        > > the delimiter ("::" in the example).[/color]
        >
        > Don't use form fields to store data: javascript provides data storage
        > for programming.[/color]

        When you say "don't" you mean you "wouldn't recommend it", presumably.
        Clearly either solution will work and each has its advantages and
        disadvantages.


        Comment

        • RobB

          #5
          Re: Return multiple value from an option item

          Jarmo wrote:[color=blue]
          > "RobB" <ferndoc9@hotma il.com> wrote in message
          > news:1109096638 .581986.24700@g 14g2000cwa.goog legroups.com...[color=green]
          > > Jarmo wrote:[color=darkred]
          > > > "Frederic" <fh@ionicsoftDO Tcom> wrote in message
          > > > news:421b0a56$0 $2021$6c56d894@ feed0.news.be.e asynet.net...
          > > >
          > > >
          > > > <option value="myid::my code">myname
          > > >
          > > > The you can parse the value in JavaScript as necessary, splitting[/color][/color][/color]
          on[color=blue][color=green][color=darkred]
          > > > the delimiter ("::" in the example).[/color]
          > >
          > > Don't use form fields to store data: javascript provides data[/color][/color]
          storage[color=blue][color=green]
          > > for programming.[/color]
          >
          > When you say "don't" you mean you "wouldn't recommend it",[/color]
          presumably.

          You seem to be equating 'wouldn't recommend it' with 'but that's my
          opinion so don't take it seriously'.
          [color=blue]
          > Clearly either solution will work and each has its advantages and
          > disadvantages.[/color]

          And what are the (clear) advantages exactly?
          Why compel an author to corrupt - I think that's a reasonable word for
          it - form values in order to get a script to function? If a server-side
          process can print data to an option value, it can put it directly into
          JS. No?

          Comment

          • Jarmo

            #6
            Re: Return multiple value from an option item

            "RobB" <ferndoc9@hotma il.com> wrote in message
            news:1109125172 .062227.237890@ f14g2000cwb.goo glegroups.com.. .[color=blue]
            > Jarmo wrote:[color=green]
            > > "RobB" <ferndoc9@hotma il.com> wrote in message
            > > news:1109096638 .581986.24700@g 14g2000cwa.goog legroups.com...[color=darkred]
            > > > Jarmo wrote:
            > > > > "Frederic" <fh@ionicsoftDO Tcom> wrote in message
            > > > > news:421b0a56$0 $2021$6c56d894@ feed0.news.be.e asynet.net...
            > > > >
            > > > >
            > > > > <option value="myid::my code">myname
            > > > >
            > > > Don't use form fields to store data: javascript provides data
            > > > storage for programming.[/color]
            > >
            > > When you say "don't" you mean you "wouldn't recommend it",
            > > presumably.[/color]
            >
            > You seem to be equating 'wouldn't recommend it' with 'but that's my
            > opinion so don't take it seriously'.[/color]

            Not really. You appear to consider this to be a law of some kind. Clearly
            there is no such law. It's a recommendation.
            [color=blue][color=green]
            > > Clearly either solution will work and each has its advantages and
            > > disadvantages.[/color]
            >
            > And what are the (clear) advantages exactly?[/color]

            It could potentially be simpler to populate a dynamic list of id/code pairs
            from a server-side process -- trivial SQL change, perhaps. Note that I say
            'could', not 'would'.
            [color=blue]
            > Why compel an author to corrupt - I think that's a reasonable word for
            > it - form values in order to get a script to function? If a server-side
            > process can print data to an option value, it can put it directly into
            > JS. No?[/color]

            Neither of us knows exactly what the OP wants. His request was "I need to
            get the id and the code" and who's to say that they have to come in distinct
            fields? One option would be for it come back as id::code, another would be
            via your suggestion with the presumed two additional hidden fields.


            Comment

            • Frederic

              #7
              Re: Return multiple value from an option item

              Jarmo wrote:[color=blue]
              > "RobB" <ferndoc9@hotma il.com> wrote in message
              > news:1109125172 .062227.237890@ f14g2000cwb.goo glegroups.com.. .
              >[color=green]
              >>Jarmo wrote:
              >>[color=darkred]
              >>>"RobB" <ferndoc9@hotma il.com> wrote in message
              >>>news:1109096 638.581986.2470 0@g14g2000cwa.g ooglegroups.com ...
              >>>
              >>>>Jarmo wrote:
              >>>>
              >>>>>"Frederi c" <fh@ionicsoftDO Tcom> wrote in message
              >>>>>news:421b0 a56$0$2021$6c56 d894@feed0.news .be.easynet.net ...
              >>>>>
              >>>>>
              >>>>><option value="myid::my code">myname
              >>>>>
              >>>>
              >>>>Don't use form fields to store data: javascript provides data
              >>>>storage for programming.
              >>>
              >>>When you say "don't" you mean you "wouldn't recommend it",
              >>>presumably .[/color]
              >>
              >>You seem to be equating 'wouldn't recommend it' with 'but that's my
              >>opinion so don't take it seriously'.[/color]
              >
              >
              > Not really. You appear to consider this to be a law of some kind. Clearly
              > there is no such law. It's a recommendation.
              >
              >[color=green][color=darkred]
              >>>Clearly either solution will work and each has its advantages and
              >>>disadvantage s.[/color]
              >>
              >>And what are the (clear) advantages exactly?[/color]
              >
              >
              > It could potentially be simpler to populate a dynamic list of id/code pairs
              > from a server-side process -- trivial SQL change, perhaps. Note that I say
              > 'could', not 'would'.
              >
              >[color=green]
              >>Why compel an author to corrupt - I think that's a reasonable word for
              >>it - form values in order to get a script to function? If a server-side
              >>process can print data to an option value, it can put it directly into
              >>JS. No?[/color]
              >
              >
              > Neither of us knows exactly what the OP wants. His request was "I need to
              > get the id and the code" and who's to say that they have to come in distinct
              > fields? One option would be for it come back as id::code, another would be
              > via your suggestion with the presumed two additional hidden fields.
              >
              >[/color]

              OK don't fight :-)
              I used the method Jarmo proposed before reading it, but RobB's one is
              good too, maybe cleaner because the separation between HTML and code is
              better.

              Thanks everybody

              Fred

              Comment

              • RobB

                #8
                Re: Return multiple value from an option item

                Frederic wrote:

                (snip)
                [color=blue]
                > OK don't fight :-)
                > I used the method Jarmo proposed before reading it, but RobB's one is[/color]
                [color=blue]
                > good too, maybe cleaner because the separation between HTML and code[/color]
                is[color=blue]
                > better.[/color]

                Got it. Cleanliness is next to that other thing.

                1) Structural Layer (X/HTML)
                2) Presentational Layer (CSS)
                3) Behavioral layer (JavaScript)
                [color=blue]
                > Thanks everybody
                >
                > Fred[/color]

                De nada.

                Comment

                • Fred Oz

                  #9
                  Re: Return multiple value from an option item

                  RobB wrote:
                  [...][color=blue]
                  > 1) Structural Layer (X/HTML)
                  > 2) Presentational Layer (CSS)
                  > 3) Behavioral layer (JavaScript)[/color]

                  Data layer?

                  For any serious processing, it's back on the server - JavaScript
                  has little to offer. Now if the OP was after a Java app...

                  --
                  Fred

                  Comment

                  Working...