[thelist] ASP & HTML: Pass double data from a Select

rudy rudy937 at rogers.com
Tue Jul 15 20:00:44 CDT 2003

> <select name='fruit'>
>      <option value='1'>apples</option>
>      <option value='2'>peaches</option>
> </select>
> I need to pass BOTH the value (1 or 2) and the user-visible options
> (apples or peaches).  Before committing to the database, which will
> contain the value (1 or 2) the user will have a preview page, which will
> need to show the fruit they selected.  1 and 2 mean nothing to the user.

well, three different people have already given you three different

some of them quite complex

care for a fourth?  a much easier solution?

don't pass the number, just pass the value

      <option value="apples">apples</option>
      <option value="peaches">peaches</option>

(aside: i always use double quotes in (x)html, don't ask me why)

sending the values is actually the simplest solution, from several different

and if you know me, you know how i love simple solutions

of course, what you have to do on the back end is (re)translate the passed
value back into its primary key value, since of course you want to store the
PK value in whatever detail table you're storing the user's choice in,

but doing a lookup to translate peaches into 2 is not a "round trip" to the
server, it is done after the user has confirmed her choice -- peaches

and depending on how you do your insert into the target table, you may
not even need a separate lookup, you might be able to do it with a simple

PKs are a lovely idea because of the space savings they afford inside a
table, but when you are dealing with one record (as you are on a form),
there's no noticeable difference in performance efficiency if you send the
value to the form instead of the PK

and in case you're wondering about spoofing, of course whether it's peaches
or 2, you are still exposed to the same risk -- the spoofer would just
submit apricots instead of 3, whichever

how many people, when validating a form submission from the web, actually
take the trouble to look up a PK that came from a value of a dropdown list
that was generated from a lookup table?

you should, eh, because you are just as likely to get a PK spoofed as a

anyway, back to your question...

SUMMARY:  use values

the user confirmation page is trivial, and on the back end, just do a
"reverse lookup" of the selected value in the lookup

neat, eh?


More information about the thelist mailing list