Can an Option in a Select tag carry multiple values?

user327712 picture user327712 · Jul 14, 2010 · Viewed 236.6k times · Source

I got a select tag with some options in a HTML form:
(the data will be collected and processed using PHP)

Testing:

<select name="Testing">  
  <option value="1"> One  
  <option value="2"> Two  
  <option value="3"> Three
</select>

Is it possible for an option to carry multiple values like when a user selects "One", then a few other values related to this option will be written to the Database.

How should I design the select Tag so that each of the options can carry one than one value like this:

<select name="Testing">  
  <option value="1" value="2010"> One  
  <option value="2" value="2122"> Two  
  <option value="3" value="0"> Three
</select>

Answer

Robusto picture Robusto · Jul 14, 2010

One way to do this, first one an array, 2nd an object:

    <select name="">
        <option value='{"num_sequence":[0,1,2,3]}'>Option one</option>
        <option value='{"foo":"bar","one":"two"}'>Option two</option>
    </select>

Edited (3 years after answering) to put both values into JSON format (using JSON.stringify()) because of a complaint that my proof-of-concept answer "could confuse a newbie developer."