htp.formselectoption single description and multiple values

Melodi Roberts
Melodi Roberts used Ask the Experts™
I need to store valid degree codes, major codes and concentration codes separately, while displaying the descriptions for these in a form list of values all concatenated together.

Is there a way to display a single description (value) , but store in more than one form element (name)?

I can store the degree, major and concentration codes as one value and then parse out the codes from this; however, it seems there should be an easier way.  Perhaps there is some way that I can use javascript on the form.selectoption??

Thanks for any tips.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Engineer
If you're talking about static data you could do something like this:

  <title> Q_27726076 </title>
  <script type="text/javascript">

   var opts = [
     [1, 'degree 1', 'major 1', 'concentration 1']
    ,[2, 'degree 2', 'major 2', 'concentration 2']
    ,[6, 'degree 6', 'major 6', 'concentration 6']
    ,[7, 'degree 7', 'major 7', 'concentration 7']

   var elemopts = null;
   function initopts() {
    elemopts = document.forms['frm'].elements['opts'];
	for (var opt = 0; opt < opts.length; opt++) {
	 elemopts.options.add(new Option(opts[opt][1] + ", " + opts[opt][2] + ", " + opts[opt][3], opts[opt][0]));

   function setopt() {
	var selopt = elemopts.selectedIndex-1; // -1 to skip the 'please select'
	document.forms['frm'].elements['selected'].value      = opts[selopt][0];
	document.forms['frm'].elements['degree'].value        = opts[selopt][1];
	document.forms['frm'].elements['major'].value         = opts[selopt][2];
	document.forms['frm'].elements['concentration'].value = opts[selopt][3];

 <body onload="initopts()">
  <form name="frm" action="" method="post">
   <select name="opts" onchange="setopt()"><option>-- please select...</option>
   <input type="hidden" name="selected">
   <input type="hidden" name="degree">
   <input type="hidden" name="major">
   <input type="hidden" name="concentration">
   <input type="submit">

Open in new window

If you're using a database and server side code to generate the data, you can still do this but then there might be a simpler solution, generating the options as the page is built.
Melodi RobertsProgrammer/Analyst


Thank you for your feedback. I have not had time to get back to this code as I am working on another project.  I am sure that this will help so will accept this as an answer and close it out. Thanks so much.
Melodi RobertsProgrammer/Analyst


Thank you so much. I am learning so much with the example you posted.
Robert SchuttSoftware Engineer

Glad to help. Please do return here to post your findings when you have checked it out because there is a chance other people find this solution when struggling with a similar problem and if it didn't help you it could be important for them to know why/how. I will keep monitoring so a follow-up question is possible.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial