Items Selected In List

[Total: 0    Average: 0/5]

This shows how you can determine which items in a select list are selected.

Head Code:

<script language="JavaScript">
<!--
function showItem(selField) {
  var optText = "";
  var counter = 1;
  for (var i=0; i < selField.length; i++) {
      if (selField[i].selected) {
         optText += counter +
                    ". " +
                    selField[i].text +
                    "n";
         counter ++;
      }
  }
  if (counter==1)
     alert("No items have been selected.");
  else
     alert("Items selected:n" + optText);
}
//-->
</script>

Body Code:

<form name="form1">
Which Web-browsers have you used?<br>May choose some<br>
<select name="selObj1" multiple>
<option>Navigator 3.0
<option>Navigator 4.0
<option>NCSA Mosaic 2.0
<option>MSIE 3.0
<option>MSIE 4.0
<option>MSIE 5.0
</select>
<p>
<input type="button"
       value="See value"
       onClick="showItem(this.form.selObj1)">
</form>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *