By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,793 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,793 IT Pros & Developers. It's quick & easy.

How do I read which items have been selected in a multiple listbox

Claus Mygind
100+
P: 571
After the user has made their selection from a multiple select box how can I read the options array to see which items were selected

Expand|Select|Wrap|Line Numbers
  1.  
  2. <select
  3.   id  ="PHASECODE"
  4.   name="PHASECODE"
  5.   multiple="multiple"
  6.   size="10"
  7.   onblur="readSelect();"
  8. >
  9.  <option value="10">10. Drilling</option>
  10.  <option value="15">15. Layout</option>
  11.  <option value="30">30. Geotechnical Eng.</option>
  12.  <option value="40">40. Enviromental</option>
  13.  <option value="50">50. Design Services</option>
  14.  <option value="60">60. Construction Material Eng.</option>
  15.  <option value="70">70. Concrete and Asphalt Lab.</option>
  16.  <option value="80">80. Soils Lab.</option>
  17.  <option value="92">92. Maint. Shop Activites</option>
  18. </select>
  19.  
  20.  
  21. function readSelect()
  22. {
  23. //how do I determine which items were selected.
  24. }
  25.  
  26.  
Oct 27 '08 #1
Share this Question
Share on Google+
1 Reply


Claus Mygind
100+
P: 571
Ok I think I got it figured out.

Expand|Select|Wrap|Line Numbers
  1. function readSelect()
  2. {
  3.  for (var i = 0; i < document.getElementById("PHASECODE").options.length; i++ )
  4.  {
  5.   if ( document.getElementById("PHASECODE").options[i].selected )
  6.   {
  7.    alert(document.getElementById("PHASECODE").options[i].value);
  8.   }
  9.  }
  10. }
  11.  
Oct 27 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.