html select storing more than one value against an option

Hi all,

I would like to be able to show a select box on my webpage which shows names. Against each name I would like to store a code AND a short description. Can this be done?

Thanks

Duncan
DuncanRichardsonAsked:
Who is Participating?
 
HonorGodSoftware EngineerCommented:
Something like this perhaps?h
<html>
<head>
<title> Extra Select stuff </title>
<script type="text/javascript">
  var stuff = { 'Tom'  : [ 1.23, 'Tom stuff' ],
                'Dick' : [ 3.45, 'Dick stuff' ],
                'Harry' : [ 5.67, 'Harry stuff' ]
              }
 
  function pick( name ) {
    alert( name + ' -> ' + stuff[ name ] )
  }
</script>
</head>
<body>
 <select onchange='pick(this.options[this.selectedIndex].value)'>
   <option value=''>Pick...</option>
   <option>Tom</option>
   <option>Dick</option>
   <option>Harry></option>
 </select>
 
</body>
</html>

Open in new window

0
 
HonorGodSoftware EngineerCommented:
Well, you could have a data structure (e.g., a dictionary) that could be used to hold whatever information that you want/need that was associated with the select options.

For example, the dictionary key could be the names from the select list, and the value could be the code and description.

Does this make sense?
0
 
DuncanRichardsonAuthor Commented:
Can this be done in javascript?
0
 
HonorGodSoftware EngineerCommented:
Thanks for the grade & points.

I'm sorry that you didn't think the answer warranted and A.

Good luck & have a great day.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.